1use std::fmt;
2
3use orpc::ORPCError;
4
5#[derive(Debug)]
10pub enum ClientError {
11 Transport(reqwest::Error),
13 Serialize(serde_json::Error),
15 Deserialize(serde_json::Error),
17 Rpc(ORPCError),
19 Sse(String),
21}
22
23impl fmt::Display for ClientError {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 ClientError::Transport(e) => write!(f, "transport error: {e}"),
27 ClientError::Serialize(e) => write!(f, "serialize error: {e}"),
28 ClientError::Deserialize(e) => write!(f, "deserialize error: {e}"),
29 ClientError::Rpc(e) => write!(f, "rpc error: {e}"),
30 ClientError::Sse(msg) => write!(f, "sse error: {msg}"),
31 }
32 }
33}
34
35impl std::error::Error for ClientError {
36 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
37 match self {
38 ClientError::Transport(e) => Some(e),
39 ClientError::Serialize(e) => Some(e),
40 ClientError::Deserialize(e) => Some(e),
41 ClientError::Rpc(e) => Some(e),
42 _ => None,
43 }
44 }
45}
46
47impl From<reqwest::Error> for ClientError {
48 fn from(err: reqwest::Error) -> Self {
49 ClientError::Transport(err)
50 }
51}
52
53impl From<ORPCError> for ClientError {
54 fn from(err: ORPCError) -> Self {
55 ClientError::Rpc(err)
56 }
57}