From cd6ce7caf5d3bb8cc3466300c6bc2164bb142915 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Fri, 16 Feb 2024 16:09:38 +0100 Subject: [PATCH] fix: clean up --- relay_client/src/error.rs | 2 +- relay_rpc/src/rpc/error.rs | 32 ++++++++++++++++---------------- relay_rpc/src/rpc/tests.rs | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/relay_client/src/error.rs b/relay_client/src/error.rs index b2a5f8a..eeb79ce 100644 --- a/relay_client/src/error.rs +++ b/relay_client/src/error.rs @@ -75,7 +75,7 @@ impl From for ClientError { } #[derive(Debug, thiserror::Error)] -pub enum Error { +pub enum Error { /// Client errors encountered while performing the request. #[error(transparent)] Client(ClientError), diff --git a/relay_rpc/src/rpc/error.rs b/relay_rpc/src/rpc/error.rs index aa650db..07112f2 100644 --- a/relay_rpc/src/rpc/error.rs +++ b/relay_rpc/src/rpc/error.rs @@ -102,7 +102,7 @@ pub enum InternalError { /// into [`super::ErrorResponse`], and should be specific enough for the clients /// to make sense of the problem. #[derive(Debug, thiserror::Error, strum::IntoStaticStr, PartialEq, Eq)] -pub enum Error { +pub enum Error { #[error("Auth error: {0}")] Auth(#[from] AuthError), @@ -122,11 +122,11 @@ pub enum Error { impl Error { pub fn code(&self) -> i32 { match self { - Self::Auth(_) => ERROR_CODE_AUTH, - Self::TooManyRequests => ERROR_CODE_TOO_MANY_REQUESTS, - Self::Payload(_) => ERROR_CODE_PAYLOAD, - Self::Handler(_) => ERROR_CODE_HANDLER, - Self::Internal(_) => ERROR_CODE_INTERNAL, + Self::Auth(_) => CODE_AUTH, + Self::TooManyRequests => CODE_TOO_MANY_REQUESTS, + Self::Payload(_) => CODE_PAYLOAD, + Self::Handler(_) => CODE_HANDLER, + Self::Internal(_) => CODE_INTERNAL, } } @@ -141,11 +141,11 @@ impl Error { } } -pub const ERROR_CODE_AUTH: i32 = 3000; -pub const ERROR_CODE_TOO_MANY_REQUESTS: i32 = 3001; -pub const ERROR_CODE_PAYLOAD: i32 = -32600; -pub const ERROR_CODE_HANDLER: i32 = -32000; -pub const ERROR_CODE_INTERNAL: i32 = -32603; +pub const CODE_AUTH: i32 = 3000; +pub const CODE_TOO_MANY_REQUESTS: i32 = 3001; +pub const CODE_PAYLOAD: i32 = -32600; +pub const CODE_HANDLER: i32 = -32000; +pub const CODE_INTERNAL: i32 = -32603; #[derive(Debug, thiserror::Error)] #[error("Invalid error data")] @@ -158,11 +158,11 @@ impl TryFrom for Error { let tag = &err.data; let err = match err.code { - ERROR_CODE_AUTH => Error::Auth(try_parse_error(tag)?), - ERROR_CODE_TOO_MANY_REQUESTS => Error::TooManyRequests, - ERROR_CODE_PAYLOAD => Error::Payload(try_parse_error(tag)?), - ERROR_CODE_HANDLER => Error::Handler(try_parse_error(tag)?), - ERROR_CODE_INTERNAL => Error::Internal(try_parse_error(tag)?), + CODE_AUTH => Error::Auth(try_parse_error(tag)?), + CODE_TOO_MANY_REQUESTS => Error::TooManyRequests, + CODE_PAYLOAD => Error::Payload(try_parse_error(tag)?), + CODE_HANDLER => Error::Handler(try_parse_error(tag)?), + CODE_INTERNAL => Error::Internal(try_parse_error(tag)?), _ => return Err(InvalidErrorData), }; diff --git a/relay_rpc/src/rpc/tests.rs b/relay_rpc/src/rpc/tests.rs index 1fbb0f3..94a5d67 100644 --- a/relay_rpc/src/rpc/tests.rs +++ b/relay_rpc/src/rpc/tests.rs @@ -592,7 +592,7 @@ fn validation() { }; assert_eq!(request.validate(), Ok(())); - // Batch receive: empty list.PayloadError + // Batch receive: empty list. let request = Request { id, jsonrpc: jsonrpc.clone(),