use reqwest::StatusCode;
#[derive(Debug)]
#[allow(clippy::absolute_paths)]
pub enum GazelleError {
Request(reqwest::Error),
Deserialization(serde_json::Error, String),
IO(std::io::Error),
BadRequest,
Unauthorized,
NotFound,
TooManyRequests,
Other(StatusCode, String),
}
impl GazelleError {
pub(crate) fn from_status_code(status_code: StatusCode) -> Option<Self> {
match status_code {
StatusCode::BAD_REQUEST => Some(GazelleError::BadRequest),
StatusCode::UNAUTHORIZED => Some(GazelleError::Unauthorized),
StatusCode::NOT_FOUND => Some(GazelleError::NotFound),
StatusCode::TOO_MANY_REQUESTS => Some(GazelleError::TooManyRequests),
_ => None,
}
}
pub(crate) fn from_str(value: &str) -> Option<Self> {
match value {
"bad id parameter" | "bad parameters" => Some(GazelleError::BadRequest),
"This page is limited to API key usage only." | "This page requires an api token" => {
Some(GazelleError::Unauthorized)
}
"endpoint not found" | "failure" => Some(GazelleError::NotFound),
"Rate limit exceeded" => Some(GazelleError::TooManyRequests),
_ => None,
}
}
}