use thiserror::Error;
#[derive(Error, Debug)]
pub enum KobeApiError {
#[error("HTTP request failed: {0}")]
HttpError(#[from] reqwest::Error),
#[error("JSON error: {0}")]
JsonError(#[from] serde_json::Error),
#[error("API error: {status_code} - {message}")]
ApiError { status_code: u16, message: String },
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("Resource not found: {0}")]
NotFound(String),
#[error("Rate limit exceeded. Please try again later.")]
RateLimitExceeded,
#[error("Request timed out")]
Timeout,
#[error("Invalid URL: {0}")]
InvalidUrl(String),
#[error("An error occurred: {0}")]
Other(String),
}
impl KobeApiError {
pub fn api_error(status_code: u16, message: impl Into<String>) -> Self {
KobeApiError::ApiError {
status_code,
message: message.into(),
}
}
pub fn invalid_parameter(message: impl Into<String>) -> Self {
KobeApiError::InvalidParameter(message.into())
}
pub fn is_rate_limit(&self) -> bool {
matches!(self, KobeApiError::RateLimitExceeded)
}
pub fn is_not_found(&self) -> bool {
matches!(self, KobeApiError::NotFound(_))
}
}