pub struct ErrorPayload<ErrData = Box<RawValue>> {
pub code: i64,
pub message: Cow<'static, str>,
pub data: Option<ErrData>,
}
Expand description
A JSON-RPC 2.0 error object.
This response indicates that the server received and handled the request,
but that there was an error in the processing of it. The error should be
included in the message
field of the response payload.
Fields§
§code: i64
The error code.
message: Cow<'static, str>
The error message (if any).
data: Option<ErrData>
The error data (if any).
Implementations§
source§impl<E> ErrorPayload<E>
impl<E> ErrorPayload<E>
sourcepub const fn parse_error() -> Self
pub const fn parse_error() -> Self
Create a new error payload for a parse error.
sourcepub const fn invalid_request() -> Self
pub const fn invalid_request() -> Self
Create a new error payload for an invalid request.
sourcepub const fn method_not_found() -> Self
pub const fn method_not_found() -> Self
Create a new error payload for a method not found error.
sourcepub const fn invalid_params() -> Self
pub const fn invalid_params() -> Self
Create a new error payload for an invalid params error.
sourcepub const fn internal_error() -> Self
pub const fn internal_error() -> Self
Create a new error payload for an internal error.
sourcepub const fn internal_error_message(message: Cow<'static, str>) -> Self
pub const fn internal_error_message(message: Cow<'static, str>) -> Self
Create a new error payload for an internal error with a custom message.
sourcepub const fn internal_error_with_obj(data: E) -> Selfwhere
E: RpcObject,
pub const fn internal_error_with_obj(data: E) -> Selfwhere
E: RpcObject,
Create a new error payload for an internal error with a custom message and additional data.
sourcepub const fn internal_error_with_message_and_obj(
message: Cow<'static, str>,
data: E,
) -> Selfwhere
E: RpcObject,
pub const fn internal_error_with_message_and_obj(
message: Cow<'static, str>,
data: E,
) -> Selfwhere
E: RpcObject,
Create a new error payload for an internal error with a custom message
sourcepub fn is_retry_err(&self) -> bool
pub fn is_retry_err(&self) -> bool
Analyzes the ErrorPayload and decides if the request should be retried based on the error code or the message.
source§impl<E> ErrorPayload<E>where
E: RpcObject,
impl<E> ErrorPayload<E>where
E: RpcObject,
sourcepub fn serialize_payload(&self) -> Result<ErrorPayload>
pub fn serialize_payload(&self) -> Result<ErrorPayload>
Serialize the inner data into a RawValue
.
source§impl ErrorPayload<&RawValue>
impl ErrorPayload<&RawValue>
sourcepub fn into_owned(self) -> ErrorPayload
pub fn into_owned(self) -> ErrorPayload
Convert this borrowed error payload into an owned payload by copying the data from the deserializer (if necessary).
source§impl<'a, Data> ErrorPayload<Data>
impl<'a, Data> ErrorPayload<Data>
sourcepub fn try_data_as<T: Deserialize<'a>>(&'a self) -> Option<Result<T>>
pub fn try_data_as<T: Deserialize<'a>>(&'a self) -> Option<Result<T>>
Deserialize the error’s data
field, borrowing from the data field if
necessary.
§Returns
None
if the error has nodata
field.Some(Ok(data))
if the error has adata
field that can be deserialized.Some(Err(err))
if the error has adata
field that can’t be deserialized.
sourcepub fn deser_data<T: DeserializeOwned>(self) -> Result<ErrorPayload<T>, Self>
pub fn deser_data<T: DeserializeOwned>(self) -> Result<ErrorPayload<T>, Self>
Attempt to deserialize the data field.
§Returns
Ok(ErrorPayload<T>)
if the data field can be deserializedErr(self)
if the data field can’t be deserialized, or if there is no data field.
sourcepub fn as_revert_data(&self) -> Option<Bytes>
pub fn as_revert_data(&self) -> Option<Bytes>
Attempt to extract revert data from the JsonRpcError be recursively traversing the error’s data field
This returns the first hex it finds in the data object, and its
behavior may change with serde_json
internal changes.
If no hex object is found, it will return an empty bytes IFF the error is a revert
Inspired by ethers-js logic: https://github.com/ethers-io/ethers.js/blob/9f990c57f0486728902d4b8e049536f2bb3487ee/packages/providers/src.ts/json-rpc-provider.ts#L25-L53
sourcepub fn as_decoded_error<E: SolInterface>(&self, validate: bool) -> Option<E>
pub fn as_decoded_error<E: SolInterface>(&self, validate: bool) -> Option<E>
Extracts revert data and tries decoding it into given custom errors set.
Trait Implementations§
source§impl<ErrData: Clone> Clone for ErrorPayload<ErrData>
impl<ErrData: Clone> Clone for ErrorPayload<ErrData>
source§fn clone(&self) -> ErrorPayload<ErrData>
fn clone(&self) -> ErrorPayload<ErrData>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<ErrData: Debug> Debug for ErrorPayload<ErrData>
impl<ErrData: Debug> Debug for ErrorPayload<ErrData>
source§impl<'de, ErrData: Deserialize<'de>> Deserialize<'de> for ErrorPayload<ErrData>
impl<'de, ErrData: Deserialize<'de>> Deserialize<'de> for ErrorPayload<ErrData>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<ErrData: Display> Display for ErrorPayload<ErrData>
impl<ErrData: Display> Display for ErrorPayload<ErrData>
source§impl<T> From<T> for ErrorPayload<T>
impl<T> From<T> for ErrorPayload<T>
source§impl<ErrData: PartialEq> PartialEq for ErrorPayload<ErrData>
impl<ErrData: PartialEq> PartialEq for ErrorPayload<ErrData>
source§impl<ErrData> Serialize for ErrorPayload<ErrData>where
ErrData: Serialize,
impl<ErrData> Serialize for ErrorPayload<ErrData>where
ErrData: Serialize,
impl<ErrData: Eq> Eq for ErrorPayload<ErrData>
impl<ErrData> StructuralPartialEq for ErrorPayload<ErrData>
Auto Trait Implementations§
impl<ErrData> Freeze for ErrorPayload<ErrData>where
ErrData: Freeze,
impl<ErrData> RefUnwindSafe for ErrorPayload<ErrData>where
ErrData: RefUnwindSafe,
impl<ErrData> Send for ErrorPayload<ErrData>where
ErrData: Send,
impl<ErrData> Sync for ErrorPayload<ErrData>where
ErrData: Sync,
impl<ErrData> Unpin for ErrorPayload<ErrData>where
ErrData: Unpin,
impl<ErrData> UnwindSafe for ErrorPayload<ErrData>where
ErrData: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)