use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("HTTP {status}: {body}")]
Http { status: u16, body: String },
#[error("Redirect to: {url}")]
Redirect { url: String },
#[error("record not found")]
NotFound,
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("URL error: {0}")]
Url(#[from] url::ParseError),
#[error("signature error: {0}")]
Signature(String),
#[error("transport error: {0}")]
Transport(String),
#[error("protocol error: {0}")]
Protocol(String),
}
#[cfg(feature = "client")]
impl From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Self {
if let Some(status) = e.status() {
Error::Http {
status: status.as_u16(),
body: e.to_string(),
}
} else {
Error::Transport(e.to_string())
}
}
}
#[cfg(feature = "websocket")]
impl From<tokio_tungstenite::tungstenite::Error> for Error {
fn from(e: tokio_tungstenite::tungstenite::Error) -> Self {
Error::Transport(e.to_string())
}
}