use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("API error {status_code}: {message}")]
Api {
status_code: u16,
message: String,
},
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("WebSocket error: {0}")]
WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("URL error: {0}")]
Url(#[from] url::ParseError),
#[error("Connection error: {0}")]
Connection(String),
#[error("Terminal connection closed")]
TerminalClosed,
}
impl Error {
pub fn api(status_code: u16, message: impl Into<String>) -> Self {
Self::Api {
status_code,
message: message.into(),
}
}
pub fn connection(message: impl Into<String>) -> Self {
Self::Connection(message.into())
}
}