Trait ethers_providers::MiddlewareError
source · pub trait MiddlewareError: Error + Sized + Send + Sync {
type Inner: MiddlewareError;
// Required methods
fn from_err(e: Self::Inner) -> Self;
fn as_inner(&self) -> Option<&Self::Inner>;
// Provided methods
fn is_inner(&self) -> bool { ... }
fn as_serde_error(&self) -> Option<&Error> { ... }
fn is_serde_error(&self) -> bool { ... }
fn as_provider_error(&self) -> Option<&ProviderError> { ... }
fn from_provider_err(p: ProviderError) -> Self { ... }
fn as_error_response(&self) -> Option<&JsonRpcError> { ... }
fn is_error_response(&self) -> bool { ... }
}
Expand description
MiddlewareError
is a companion trait to crate::Middleware
. It
describes error behavior that is common to all Middleware errors.
Like crate::Middleware
, it allows moving down through layered errors.
Like RpcError
it exposes convenient accessors to useful underlying
error information.
§Not to Devs:
While this trait includes the same methods as RpcError
, it is not a
supertrait. This is so that 3rd party developers do not need to learn and
implement both traits. We provide default methods that delegate to inner
middleware errors on the assumption that it will eventually reach a
ProviderError
, which has correct behavior. This allows Middleware devs
to ignore the methods’ presence if they want. Middleware are already plenty
complicated and we don’t need to make it worse :)
Required Associated Types§
sourcetype Inner: MiddlewareError
type Inner: MiddlewareError
The Inner
type is the next lower middleware layer’s error type.
Required Methods§
Provided Methods§
sourcefn is_inner(&self) -> bool
fn is_inner(&self) -> bool
Returns true
if the underlying error stems from a lower middleware
layer
sourcefn as_serde_error(&self) -> Option<&Error>
fn as_serde_error(&self) -> Option<&Error>
Access an underlying serde_json
error (if any)
Attempts to access an underlying serde_json::Error
. If the
underlying error is not a serde_json error, this function will return
None
.
§Implementor’s Note:
When writing a custom middleware, if your middleware uses serde_json
we recommend a custom implementation of this method. It should first
check your Middleware’s error for local serde_json
errors, and then
delegate to inner if none is found. Failing to implement this method may
result in missed serde_json
errors.
sourcefn is_serde_error(&self) -> bool
fn is_serde_error(&self) -> bool
Returns true
if the underlying error is a serde_json (de)serialization
error. This method can be used to identify
sourcefn as_provider_error(&self) -> Option<&ProviderError>
fn as_provider_error(&self) -> Option<&ProviderError>
Attempts to access an underlying ProviderError
, usually by
traversing the entire middleware stack. Access fails if the underlying
error is not a ProviderError
sourcefn from_provider_err(p: ProviderError) -> Self
fn from_provider_err(p: ProviderError) -> Self
Convert a ProviderError
to this type, by successively wrapping it
in the error types of all lower middleware
sourcefn as_error_response(&self) -> Option<&JsonRpcError>
fn as_error_response(&self) -> Option<&JsonRpcError>
Access an underlying JSON-RPC error (if any)
Attempts to access an underlying JsonRpcError
. If the underlying
error is not a JSON-RPC error response, this function will return
None
.
sourcefn is_error_response(&self) -> bool
fn is_error_response(&self) -> bool
Returns true
if the underlying error is a JSON-RPC error response
Object Safety§
Implementors§
source§impl MiddlewareError for ProviderError
impl MiddlewareError for ProviderError
type Inner = ProviderError
source§impl<M: Middleware> MiddlewareError for DevRpcMiddlewareError<M>
Available on crate feature dev-rpc
only.
impl<M: Middleware> MiddlewareError for DevRpcMiddlewareError<M>
dev-rpc
only.