mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-29 19:04:27 +00:00
Correctly encode/decode RPC errors (#1157)
This commit is contained in:
@@ -181,13 +181,13 @@ pub enum RPCCodedResponse<T: EthSpec> {
|
||||
Success(RPCResponse<T>),
|
||||
|
||||
/// The response was invalid.
|
||||
InvalidRequest(ErrorMessage),
|
||||
InvalidRequest(String),
|
||||
|
||||
/// The response indicates a server error.
|
||||
ServerError(ErrorMessage),
|
||||
ServerError(String),
|
||||
|
||||
/// There was an unknown response.
|
||||
Unknown(ErrorMessage),
|
||||
Unknown(String),
|
||||
|
||||
/// Received a stream termination indicating which response is being terminated.
|
||||
StreamTermination(ResponseTermination),
|
||||
@@ -222,7 +222,7 @@ impl<T: EthSpec> RPCCodedResponse<T> {
|
||||
}
|
||||
|
||||
/// Builds an RPCCodedResponse from a response code and an ErrorMessage
|
||||
pub fn from_error(response_code: u8, err: ErrorMessage) -> Self {
|
||||
pub fn from_error(response_code: u8, err: String) -> Self {
|
||||
match response_code {
|
||||
1 => RPCCodedResponse::InvalidRequest(err),
|
||||
2 => RPCCodedResponse::ServerError(err),
|
||||
@@ -268,18 +268,6 @@ impl<T: EthSpec> RPCCodedResponse<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Debug, Clone)]
|
||||
pub struct ErrorMessage {
|
||||
/// The UTF-8 encoded Error message string.
|
||||
pub error_message: Vec<u8>,
|
||||
}
|
||||
|
||||
impl std::string::ToString for ErrorMessage {
|
||||
fn to_string(&self) -> String {
|
||||
String::from_utf8(self.error_message.clone()).unwrap_or_else(|_| "".into())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RPCResponseErrorCode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let repr = match self {
|
||||
|
||||
Reference in New Issue
Block a user