1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("API error {status_code}: {message}")]
13 Api {
14 status_code: u16,
15 message: String,
16 },
17
18 #[error("HTTP error: {0}")]
20 Http(#[from] reqwest::Error),
21
22 #[error("WebSocket error: {0}")]
24 WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
25
26 #[error("JSON error: {0}")]
28 Json(#[from] serde_json::Error),
29
30 #[error("URL error: {0}")]
32 Url(#[from] url::ParseError),
33
34 #[error("Connection error: {0}")]
36 Connection(String),
37
38 #[error("Terminal connection closed")]
40 TerminalClosed,
41}
42
43impl Error {
44 pub fn api(status_code: u16, message: impl Into<String>) -> Self {
46 Self::Api {
47 status_code,
48 message: message.into(),
49 }
50 }
51
52 pub fn connection(message: impl Into<String>) -> Self {
54 Self::Connection(message.into())
55 }
56}