1use serde_json::Value;
2
3pub trait ProtocolError: core::fmt::Debug + Send + Sync + Sized + 'static {
7 fn code(&self) -> &str;
8 fn description(&self) -> &str;
9 fn details(&self) -> &Value;
10 fn not_implemented(action: &str) -> Self;
11 fn from_wire(code: &str, description: &str, details: Value) -> Self;
12}
13
14#[derive(Debug)]
17pub enum ClientError<E> {
18 Protocol(E),
20 Timeout,
22 Decode(serde_json::Error),
24 Transport(crate::transport::TransportError),
26 Closed,
28}
29
30impl<E: ProtocolError> core::fmt::Display for ClientError<E> {
31 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
32 match self {
33 ClientError::Protocol(e) => {
34 write!(f, "protocol error: {} ({})", e.code(), e.description())
35 }
36 ClientError::Timeout => write!(f, "request timed out"),
37 ClientError::Decode(e) => write!(f, "failed to decode payload: {e}"),
38 ClientError::Transport(e) => write!(f, "transport error: {e}"),
39 ClientError::Closed => write!(f, "connection closed"),
40 }
41 }
42}
43
44impl<E: ProtocolError> core::error::Error for ClientError<E> {}