pub struct Error {
pub code: i32,
pub message: String,
pub data: Option<Value>,
}Expand description
JSON-RPC 2.0 error object
Fields§
§code: i32§message: String§data: Option<Value>Implementations§
Source§impl Error
impl Error
Sourcepub fn is_parse_error(&self) -> bool
pub fn is_parse_error(&self) -> bool
Check if this is a parse error (-32700)
Sourcepub fn is_invalid_request(&self) -> bool
pub fn is_invalid_request(&self) -> bool
Check if this is an invalid request error (-32600)
Sourcepub fn is_method_not_found(&self) -> bool
pub fn is_method_not_found(&self) -> bool
Check if this is a method not found error (-32601)
pub fn is_invalid_params(&self) -> bool
pub fn is_internal_error(&self) -> bool
pub fn is_server_error(&self) -> bool
pub fn code(&self) -> i32
pub fn message(&self) -> &str
pub fn data(&self) -> Option<&Value>
Sourcepub fn sanitized_with<F>(&self, transform: F) -> Selfwhere
F: FnOnce(&Self) -> Self,
pub fn sanitized_with<F>(&self, transform: F) -> Selfwhere
F: FnOnce(&Self) -> Self,
Transform this error using a custom callback function
This allows library users to implement their own error sanitization logic based on their security requirements.
§Example
let sanitized = error.sanitized_with(|err| {
if err.code() == INTERNAL_ERROR {
Error::new(err.code(), "Internal server error")
} else {
err.clone()
}
});Sourcepub fn from_error_logged(error: &dyn Error) -> Self
pub fn from_error_logged(error: &dyn Error) -> Self
Create a generic internal error from any std::error::Error
This logs the full error details server-side and returns a generic error. Use this with sanitized_with() for custom error transformation.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Error
impl<'de> Deserialize<'de> for Error
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>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
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
Mutably borrows from an owned value. Read more