Skip to content

Commit

Permalink
feat: custom error codes (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
heilhead authored Feb 24, 2023
1 parent 690ce83 commit 87c2a08
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions relay_rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub enum ValidationError {
/// make sense of the problem.
#[derive(Debug, thiserror::Error)]
pub enum GenericError {
#[error("Authorization error: {0}")]
Authorization(BoxError),

/// Request parameters validation failed.
#[error("Request validation error: {0}")]
Validation(#[from] ValidationError),
Expand All @@ -74,11 +77,12 @@ pub enum GenericError {
}

impl GenericError {
/// The error code. These are mostly generic and carried over from the old
/// `ts-relay`.
/// The error code. These are the standard JSONRPC error codes. The Relay
/// specific errors are in 3000-4999 range to align with the websocket close
/// codes.
pub fn code(&self) -> i32 {
// Source: https://github.com/WalletConnect/rs-relay/issues/262
match self {
Self::Authorization(_) => 3000,
Self::Serialization(_) => -32700,
Self::Validation(_) => -32602,
Self::RequestMethod => -32601,
Expand Down

0 comments on commit 87c2a08

Please sign in to comment.