Struct alloy_json_rpc::ErrorPayload
source · 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§fn eq(&self, other: &ErrorPayload<ErrData>) -> bool
fn eq(&self, other: &ErrorPayload<ErrData>) -> bool
self
and other
values to be equal, and is used
by ==
.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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.