#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("{0}")]
Http(#[from] reqwest::Error),
#[error("API error (HTTP {status}): {message}")]
Api {
status: u16,
message: String,
},
#[error("invalid IP address: {0}")]
InvalidIp(String),
#[error("bulk lookup exceeds maximum of 100 IPs")]
BulkLimitExceeded,
#[error("bulk lookup requires at least one IP address")]
BulkEmpty,
}
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, serde::Deserialize)]
pub(crate) struct ApiErrorResponse {
pub message: String,
}
impl Error {
pub fn status(&self) -> Option<u16> {
match self {
Error::Api { status, .. } => Some(*status),
_ => None,
}
}
}