Skip to main content

rebind_client/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum RebindError {
5    #[error("connection error: {0}")]
6    Connection(String),
7
8    #[error("RPC timed out: {0}")]
9    Timeout(String),
10
11    #[error("server error [{code}]: {message}")]
12    Server { code: String, message: String },
13
14    #[error("websocket error: {0}")]
15    WebSocket(#[from] tungstenite::Error),
16
17    #[error("json error: {0}")]
18    Json(#[from] serde_json::Error),
19}
20
21impl RebindError {
22    pub fn connection(msg: impl Into<String>) -> Self {
23        Self::Connection(msg.into())
24    }
25
26    pub fn timeout(cmd: impl Into<String>) -> Self {
27        Self::Timeout(cmd.into())
28    }
29
30    pub fn server(code: impl Into<String>, message: impl Into<String>) -> Self {
31        Self::Server {
32            code: code.into(),
33            message: message.into(),
34        }
35    }
36}
37
38pub type Result<T> = std::result::Result<T, RebindError>;