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§

type Inner: MiddlewareError

The Inner type is the next lower middleware layer’s error type.

Required Methods§

fn from_err(e: Self::Inner) -> Self

Convert the next lower middleware layer’s error to this layer’s error

fn as_inner(&self) -> Option<&Self::Inner>

Attempt to convert this error to the next lower middleware’s error. Conversion fails if the error is not from an inner layer (i.e. the error originates at this middleware layer)

Provided Methods§

fn is_inner(&self) -> bool

Returns true if the underlying error stems from a lower middleware layer

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.

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

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]

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

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.

fn is_error_response(&self) -> bool

Returns true if the underlying error is a JSON-RPC error response

Implementations on Foreign Types§

§

impl<M> MiddlewareError for TimeLagError<M>where M: Middleware,

§

type Inner = <M as Middleware>::Error

§

fn from_err(src: <M as Middleware>::Error) -> TimeLagError<M>

§

fn as_inner(&self) -> Option<&<TimeLagError<M> as MiddlewareError>::Inner>

§

impl<M> MiddlewareError for GasEscalatorError<M>where M: Middleware,

§

type Inner = <M as Middleware>::Error

§

fn from_err(src: <M as Middleware>::Error) -> GasEscalatorError<M>

§

fn as_inner(&self) -> Option<&<GasEscalatorError<M> as MiddlewareError>::Inner>

§

impl<M> MiddlewareError for MiddlewareError<M>where M: Middleware,

§

type Inner = <M as Middleware>::Error

§

fn from_err(src: <M as Middleware>::Error) -> MiddlewareError<M>

§

fn as_inner(&self) -> Option<&<MiddlewareError<M> as MiddlewareError>::Inner>

§

impl<M> MiddlewareError for NonceManagerError<M>where M: Middleware,

§

type Inner = <M as Middleware>::Error

§

fn from_err(src: <M as Middleware>::Error) -> NonceManagerError<M>

§

fn as_inner(&self) -> Option<&<NonceManagerError<M> as MiddlewareError>::Inner>

§

impl<M, S> MiddlewareError for SignerMiddlewareError<M, S>where M: Middleware, S: Signer,

§

type Inner = <M as Middleware>::Error

§

fn from_err(src: <M as Middleware>::Error) -> SignerMiddlewareError<M, S>

§

fn as_inner( &self ) -> Option<&<SignerMiddlewareError<M, S> as MiddlewareError>::Inner>

Implementors§

§

impl MiddlewareError for ProviderError

§

type Inner = ProviderError

§

impl<M, P> MiddlewareError for PolicyMiddlewareError<M, P>where M: Middleware, P: Policy,

§

type Inner = <M as Middleware>::Error