1#[derive(thiserror::Error, Debug)]
2pub enum Error {
3 #[error("Encode error: {0}")]
4 Encode(#[from] serde_json::Error),
5 #[error("Decode error: {0}")]
6 Decode(serde_json::Error),
7 #[error("Websocket error: {0}")]
8 Websocket(#[from] tokio_tungstenite::tungstenite::Error),
9 #[error("Rpc error: {0}")]
10 Rpc(#[from] RpcError),
11 #[error("Request send error")]
12 ChannelSend,
13 #[error("Response recv error: {0}")]
14 ChannelRecv(#[from] tokio::sync::oneshot::error::RecvError),
15}
16
17#[derive(serde::Deserialize, Debug, Clone)]
18pub struct RpcError {
19 pub code: u32,
20 pub message: String,
21}
22
23impl std::fmt::Display for RpcError {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 write!(
26 f,
27 "RpcError: {{\"code\": {}, \"message\": \"{}\"}}",
28 self.code, self.message
29 )
30 }
31}
32impl std::error::Error for RpcError {}