pub type Result<T> = std::result::Result<T, BooruError>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BooruError {
#[error("HTTP request failed: {0}")]
Request(#[from] reqwest::Error),
#[error("Failed to parse API response: {0}")]
Parse(#[from] serde_json::Error),
#[error("{client} allows a maximum of {max} tags, but {actual} were provided")]
TagLimitExceeded {
client: &'static str,
max: usize,
actual: usize,
},
#[error("Post not found with ID: {0}")]
PostNotFound(u32),
#[error("Empty response from API")]
EmptyResponse,
#[error("Invalid URL: {0}")]
InvalidUrl(String),
#[error("Authentication required: {0}")]
Unauthorized(String),
#[error("Invalid tag '{tag}': {reason}")]
InvalidTag {
tag: String,
reason: String,
},
#[error("Rate limit exceeded, please wait before making more requests")]
RateLimited,
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}
impl BooruError {
#[must_use]
pub fn is_network_error(&self) -> bool {
matches!(self, Self::Request(_))
}
#[must_use]
pub fn is_parse_error(&self) -> bool {
matches!(self, Self::Parse(_))
}
#[must_use]
pub fn is_not_found(&self) -> bool {
matches!(self, Self::PostNotFound(_) | Self::EmptyResponse)
}
}