polestar_api/
error.rs

1//! Error types for the Polestar API client.
2
3use thiserror::Error;
4
5/// Errors that can occur when interacting with the Polestar API.
6#[derive(Error, Debug)]
7pub enum PolestarError {
8    /// Authentication failed (invalid or expired token).
9    #[error("Authentication failed: {0}")]
10    AuthError(String),
11
12    /// Invalid credentials provided (ERR001).
13    #[error("Invalid username or password")]
14    InvalidCredentials,
15
16    /// Token has expired and refresh failed.
17    #[error("Token expired")]
18    TokenExpired,
19
20    /// OIDC configuration unavailable.
21    #[error("OIDC configuration unavailable: {0}")]
22    OidcConfigError(String),
23
24    /// API request failed with an error message.
25    #[error("API request failed: {0}")]
26    ApiError(String),
27
28    /// Network error occurred during the request.
29    #[error("Network error: {0}")]
30    NetworkError(#[from] reqwest::Error),
31
32    /// JSON parsing error.
33    #[error("JSON parsing error: {0}")]
34    ParseError(#[from] serde_json::Error),
35
36    /// Invalid VIN provided.
37    #[error("Invalid VIN: {0}")]
38    InvalidVin(String),
39
40    /// Rate limit exceeded (HTTP 429).
41    #[error("Rate limit exceeded")]
42    RateLimitExceeded,
43
44    /// GraphQL error from the API.
45    #[error("GraphQL error: {0}")]
46    GraphQLError(String),
47}
48
49/// Convenient Result type alias for Polestar API operations.
50pub type Result<T> = std::result::Result<T, PolestarError>;