rpc_router/request/
request_parsing_error.rs

1use serde::Serialize;
2use serde_json::Value;
3use serde_with::{serde_as, DisplayFromStr};
4
5/// The RPC Request Parsing error is used when utilizing `value.try_into()?` or `Request::from_value(value)`.
6/// The design intent is to validate and provide as much context as possible when a specific validation fails.
7///
8/// Note: By design, we do not capture the "params" because they could be indefinitely large.
9///
10/// Note: In future releases, the capture of Value objects or arrays for those error variants
11///       will be replaced with Value::String containing a message such as
12///       `"[object/array redacted, 'id' must be of type number, string, or equal to null]"`
13///       or `"[object/array redacted, 'method' must be of type string]"`
14///       This approach aims to provide sufficient context for debugging the issue while preventing
15///       the capture of indefinitely large values in the logs.
16#[serde_as]
17#[derive(Debug, Serialize)]
18pub enum RequestParsingError {
19	VersionMissing {
20		id: Option<Value>,
21		method: Option<String>,
22	},
23	VersionInvalid {
24		id: Option<Value>,
25		method: Option<String>,
26		version: Value,
27	},
28
29	MethodMissing {
30		id: Option<Value>,
31	},
32	MethodInvalidType {
33		id: Option<Value>,
34		method: Value,
35	},
36
37	IdMissing {
38		method: Option<String>,
39	},
40
41	Parse(#[serde_as(as = "DisplayFromStr")] serde_json::Error),
42}
43
44impl core::fmt::Display for RequestParsingError {
45	fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::result::Result<(), core::fmt::Error> {
46		write!(fmt, "{self:?}")
47	}
48}
49
50impl std::error::Error for RequestParsingError {}