wc_data/error.rs
1//! Error and result types shared across the data layer.
2
3/// Errors surfaced by providers and the HTTP transport.
4#[derive(Debug, thiserror::Error)]
5pub enum DataError {
6 /// A network/transport-level failure (DNS, TLS, connection, timeout).
7 #[error("network error: {0}")]
8 Transport(String),
9
10 /// The upstream returned a status we treat as an error.
11 #[error("upstream returned HTTP {status}: {message}")]
12 Status {
13 /// The HTTP status code.
14 status: u16,
15 /// A short description (reason phrase or body snippet).
16 message: String,
17 },
18
19 /// The response body could not be parsed into the expected shape.
20 #[error("failed to decode response: {0}")]
21 Decode(String),
22
23 /// The provider was rate limited; `retry_after` is the server hint, if any.
24 #[error("rate limited by upstream")]
25 RateLimited {
26 /// Seconds to wait before retrying, if the server provided a hint.
27 retry_after: Option<u64>,
28 },
29
30 /// A required API key for the selected provider was not configured.
31 #[error("missing API key for the {0} provider")]
32 MissingKey(&'static str),
33
34 /// The selected provider does not support this operation (e.g. fine-grained
35 /// live events on a limited free tier).
36 #[error("operation not supported by the {provider} provider: {what}")]
37 Unsupported {
38 /// The provider name.
39 provider: &'static str,
40 /// What was requested.
41 what: &'static str,
42 },
43
44 /// Any other error with a human-readable message.
45 #[error("{0}")]
46 Other(String),
47}
48
49/// Convenience result type for the data layer.
50pub type Result<T> = std::result::Result<T, DataError>;