mindat_rs/
error.rs

1//! Error types for the Mindat API client.
2
3use thiserror::Error;
4
5/// Errors that can occur when using the Mindat API client.
6#[derive(Error, Debug)]
7pub enum MindatError {
8    /// HTTP request failed
9    #[error("HTTP request failed: {0}")]
10    Request(#[from] reqwest::Error),
11
12    /// Failed to parse URL
13    #[error("Invalid URL: {0}")]
14    Url(#[from] url::ParseError),
15
16    /// API returned an error response
17    #[error("API error (status {status}): {message}")]
18    Api { status: u16, message: String },
19
20    /// Failed to deserialize response
21    #[error("Failed to parse response: {0}")]
22    Deserialization(#[from] serde_json::Error),
23
24    /// Authentication error - missing or invalid token
25    #[error("Authentication required: please provide a valid API token")]
26    AuthenticationRequired,
27
28    /// Rate limit exceeded
29    #[error("Rate limit exceeded, please wait before making more requests")]
30    RateLimited,
31
32    /// Resource not found
33    #[error("Resource not found: {0}")]
34    NotFound(String),
35
36    /// Invalid parameter value
37    #[error("Invalid parameter: {0}")]
38    InvalidParameter(String),
39}
40
41/// Result type alias for Mindat operations.
42pub type Result<T> = std::result::Result<T, MindatError>;