pub struct Error {
pub code: i32,
pub message: String,
pub data: Option<Value>,
}
Expand description
JSON-RPC error object.
Represents an error that occurred during method execution, following the JSON-RPC 2.0 error object specification with optional additional data.
See protocol docs: JSON-RPC Error Object
Fields§
§code: i32
A number indicating the error type that occurred. This must be an integer as defined in the JSON-RPC specification.
message: String
A string providing a short description of the error. The message should be limited to a concise single sentence.
data: Option<Value>
Optional primitive or structured value that contains additional information about the error. This may include debugging information or context-specific details.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(code: impl Into<(i32, String)>) -> Self
pub fn new(code: impl Into<(i32, String)>) -> Self
Creates a new error with the given code and message.
The code parameter can be an ErrorCode
constant or a tuple of (code, message).
Sourcepub fn with_data(self, data: impl Into<Value>) -> Self
pub fn with_data(self, data: impl Into<Value>) -> Self
Adds additional data to the error.
This method is chainable and allows attaching context-specific information to help with debugging or provide more details about the error.
Sourcepub fn parse_error() -> Self
pub fn parse_error() -> Self
Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
Sourcepub fn invalid_request() -> Self
pub fn invalid_request() -> Self
The JSON sent is not a valid Request object.
Sourcepub fn method_not_found() -> Self
pub fn method_not_found() -> Self
The method does not exist / is not available.
Sourcepub fn invalid_params() -> Self
pub fn invalid_params() -> Self
Invalid method parameter(s).
Sourcepub fn internal_error() -> Self
pub fn internal_error() -> Self
Internal JSON-RPC error.
Sourcepub fn auth_required() -> Self
pub fn auth_required() -> Self
Authentication required.
Sourcepub fn resource_not_found(uri: Option<String>) -> Self
pub fn resource_not_found(uri: Option<String>) -> Self
A given resource, such as a file, was not found.
Sourcepub fn into_internal_error(err: impl Error) -> Self
pub fn into_internal_error(err: impl Error) -> Self
Converts a standard error into an internal JSON-RPC error.
The error’s string representation is included as additional data.
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>,
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl JsonSchema for Error
impl JsonSchema for Error
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref
keyword. Read more