unirate_api/error.rs
1//! Error types for the UniRate client.
2
3use thiserror::Error;
4
5/// Errors returned by [`Client`](crate::Client) methods.
6#[derive(Error, Debug)]
7#[non_exhaustive]
8pub enum UniRateError {
9 /// HTTP 401 — missing or invalid API key.
10 #[error("Authentication failed: missing or invalid API key")]
11 Authentication,
12
13 /// HTTP 429 — rate limit exceeded.
14 #[error("Rate limit exceeded")]
15 RateLimit,
16
17 /// HTTP 404 — currency not found or no data available for the requested parameters.
18 #[error("Invalid currency: currency not found or no data available")]
19 InvalidCurrency,
20
21 /// HTTP 400 — invalid request parameters (commonly bad date format).
22 #[error("Invalid date or request parameters")]
23 InvalidDate,
24
25 /// Any other non-2xx HTTP response. `403` for Pro-gated endpoints on free tier,
26 /// `503` for service unavailable, etc.
27 #[error("API error (status {status}): {body}")]
28 Api {
29 /// HTTP status code.
30 status: u16,
31 /// Raw response body.
32 body: String,
33 },
34
35 /// Transport-level / network error from `reqwest`.
36 #[error("HTTP transport error: {0}")]
37 Http(#[from] reqwest::Error),
38
39 /// JSON deserialization failure.
40 #[error("JSON decoding error: {0}")]
41 Json(#[from] serde_json::Error),
42}