use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Authentication(String),
RateLimit(String),
Validation(String),
Api { status_code: u16, message: String },
Request(String),
Parse(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Authentication(msg) => write!(f, "Authentication error: {}", msg),
Error::RateLimit(msg) => write!(f, "Rate limit exceeded: {}", msg),
Error::Validation(msg) => write!(f, "Validation error: {}", msg),
Error::Api { status_code, message } => {
write!(f, "API error (status {}): {}", status_code, message)
}
Error::Request(msg) => write!(f, "Request failed: {}", msg),
Error::Parse(msg) => write!(f, "Parse error: {}", msg),
}
}
}
impl std::error::Error for Error {}
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Self {
Error::Request(err.to_string())
}
}
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Error::Parse(err.to_string())
}
}