Skip to main content

the_odds_api/
error.rs

1//! Error types for The Odds API SDK.
2
3use thiserror::Error;
4
5/// The main error type for The Odds API SDK.
6#[derive(Error, Debug)]
7pub enum Error {
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}): {message}")]
18    Api {
19        status: u16,
20        message: String,
21    },
22
23    /// Rate limit exceeded (HTTP 429).
24    #[error("Rate limit exceeded. Requests remaining: {requests_remaining:?}")]
25    RateLimited {
26        requests_remaining: Option<u32>,
27    },
28
29    /// Invalid API key or unauthorized request (HTTP 401).
30    #[error("Unauthorized: Invalid API key")]
31    Unauthorized,
32
33    /// JSON deserialization failed.
34    #[error("Failed to deserialize response: {0}")]
35    Deserialization(#[from] serde_json::Error),
36
37    /// Missing required parameter.
38    #[error("Missing required parameter: {0}")]
39    MissingParameter(&'static str),
40
41    /// Invalid parameter value.
42    #[error("Invalid parameter value for {parameter}: {message}")]
43    InvalidParameter {
44        parameter: &'static str,
45        message: String,
46    },
47}
48
49/// A specialized Result type for The Odds API operations.
50pub type Result<T> = std::result::Result<T, Error>;