Skip to main content

govee_api2/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Error, Debug)]
6pub enum Error {
7    /// A transport-level failure (connection, TLS, timeout, ...).
8    #[error("HTTP request failed: {0}")]
9    Request(#[from] reqwest::Error),
10
11    /// The Govee API returned a non-success application code.
12    #[error("API error (code {code}): {message}")]
13    Api { code: i32, message: String },
14
15    /// The API key was rejected (HTTP 401/403).
16    #[error("invalid API key: the Govee API rejected the Govee-API-Key header")]
17    InvalidApiKey,
18
19    /// The account hit Govee's request limit (HTTP 429; 10000 requests/account/day).
20    #[error("rate limited by the Govee API{}", match .retry_after_secs {
21        Some(secs) => format!(" (retry after {secs}s)"),
22        None => String::new(),
23    })]
24    RateLimited { retry_after_secs: Option<u64> },
25
26    /// The Govee API returned a server error (HTTP 5xx), even after retries.
27    #[error("Govee API server error (HTTP {status})")]
28    Server { status: u16 },
29
30    #[error("Failed to parse JSON response: {0}")]
31    Json(#[from] serde_json::Error),
32
33    #[error("Invalid response format: {0}")]
34    InvalidResponse(String),
35
36    #[error("Device not found: {0}")]
37    DeviceNotFound(String),
38}