mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
rpc-api: use thiserror instead of derive_more for error handling (#9631)
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
@@ -28,13 +28,13 @@ pub type Result<T> = std::result::Result<T, Error>;
|
||||
pub type FutureResult<T> = jsonrpc_core::BoxFuture<Result<T>>;
|
||||
|
||||
/// State RPC errors.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// Client error.
|
||||
#[display(fmt = "Client error: {}", _0)]
|
||||
Client(Box<dyn std::error::Error + Send>),
|
||||
#[error("Client error: {}", .0)]
|
||||
Client(#[from] Box<dyn std::error::Error + Send>),
|
||||
/// Provided block range couldn't be resolved to a list of blocks.
|
||||
#[display(fmt = "Cannot resolve a block range ['{:?}' ... '{:?}]. {}", from, to, details)]
|
||||
#[error("Cannot resolve a block range ['{:?}' ... '{:?}]. {}", .from, .to, .details)]
|
||||
InvalidBlockRange {
|
||||
/// Beginning of the block range.
|
||||
from: String,
|
||||
@@ -44,7 +44,7 @@ pub enum Error {
|
||||
details: String,
|
||||
},
|
||||
/// Provided count exceeds maximum value.
|
||||
#[display(fmt = "count exceeds maximum value. value: {}, max: {}", value, max)]
|
||||
#[error("count exceeds maximum value. value: {}, max: {}", .value, .max)]
|
||||
InvalidCount {
|
||||
/// Provided value
|
||||
value: u32,
|
||||
@@ -52,16 +52,8 @@ pub enum Error {
|
||||
max: u32,
|
||||
},
|
||||
/// Call to an unsafe RPC was denied.
|
||||
UnsafeRpcCalled(crate::policy::UnsafeRpcError),
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Error::Client(ref err) => Some(&**err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
#[error(transparent)]
|
||||
UnsafeRpcCalled(#[from] crate::policy::UnsafeRpcError),
|
||||
}
|
||||
|
||||
/// Base code for all state errors.
|
||||
|
||||
Reference in New Issue
Block a user