use thiserror::Error;
#[derive(Error, Debug)]
pub enum ArxivisError {
#[error("HTTP {status}: {message}")]
Api { status: u16, message: String },
#[error("HTTP client error: {0}")]
Http(#[from] reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
}
impl ArxivisError {
pub fn is_not_found(&self) -> bool {
matches!(self, Self::Api { status: 404, .. })
}
pub fn is_unauthorized(&self) -> bool {
matches!(self, Self::Api { status: 401, .. })
}
pub fn is_rate_limited(&self) -> bool {
matches!(self, Self::Api { status: 429, .. })
}
pub fn status_code(&self) -> Option<u16> {
match self {
Self::Api { status, .. } => Some(*status),
_ => None,
}
}
}