use thiserror::Error;
#[derive(Debug, Error)]
pub enum CxError {
#[error("Authentication failed: {0}")]
Auth(String),
#[error("Permission denied: {0}")]
Permission(String),
#[error("API request failed ({status}): {message}")]
Api { status: u16, message: String },
#[error("Invalid argument: {0}")]
InvalidArgument(String),
#[error("HTTP request timed out")]
Timeout,
#[error("HTTP error: {0}")]
Http(reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Query stream error: {0}")]
QueryStream(String),
}
pub type Result<T> = std::result::Result<T, CxError>;
impl From<reqwest::Error> for CxError {
fn from(error: reqwest::Error) -> Self {
if error.is_timeout() {
Self::Timeout
} else {
Self::Http(error)
}
}
}