Skip to main content

precolator_sdk/
error.rs

1use thiserror::Error;
2
3/// Unified error type for the Precolator SDK.
4#[derive(Debug, Error)]
5pub enum PrecolatorError {
6    /// HTTP transport or TLS error from reqwest.
7    #[error("HTTP error: {0}")]
8    Http(#[from] reqwest::Error),
9
10    /// The API returned a non-success status code.
11    #[error("API error {status}: {message}")]
12    Api { status: u16, message: String },
13
14    /// A URL could not be parsed.
15    #[error("Invalid URL: {0}")]
16    InvalidUrl(#[from] url::ParseError),
17
18    /// JSON (de)serialization error.
19    #[error("Serialization error: {0}")]
20    Serialization(#[from] serde_json::Error),
21
22    /// The requested resource was not found.
23    #[error("Resource not found: {0}")]
24    NotFound(String),
25
26    /// Rate limit exceeded.
27    #[error("Rate limit exceeded — retry after {retry_after_secs}s")]
28    RateLimited { retry_after_secs: u64 },
29}
30
31/// Convenience alias used throughout the SDK.
32pub type Result<T> = std::result::Result<T, PrecolatorError>;