jsonrpc_base/error.rs
1use alloc::string::String;
2use core::fmt;
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// JSON-RPC protocol error.
7#[derive(Serialize, Deserialize, Debug, Clone)]
8pub struct Error {
9 /// Error code
10 pub code: i32,
11 /// Human-friendly message
12 pub message: String,
13 /// Underlying data
14 pub data: Option<Value>,
15}
16
17impl Error {
18 /// Protocol level parse error reserved code
19 pub const PARSE_ERROR: i32 = -32700;
20 /// Protocol level invalid request reserved code
21 pub const INVALID_REQUEST: i32 = -32600;
22}
23
24impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 write!(f, "{}", self.message)
27 }
28}