klafs_api/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur when interacting with the Klafs API
4#[derive(Error, Debug)]
5pub enum KlafsError {
6    /// Authentication failed (wrong credentials or account locked)
7    #[error("Authentication failed: {message}")]
8    AuthenticationFailed { message: String },
9
10    /// Account is locked after too many failed attempts
11    #[error("Account locked: Klafs locks accounts after 3 failed login attempts. Please wait or contact support.")]
12    AccountLocked,
13
14    /// Session expired or invalid
15    #[error("Session expired or invalid. Please login again.")]
16    SessionExpired,
17
18    /// Invalid PIN for power control
19    #[error("Invalid PIN provided")]
20    InvalidPin,
21
22    /// Sauna not found
23    #[error("Sauna with ID {sauna_id} not found")]
24    SaunaNotFound { sauna_id: String },
25
26    /// Sauna is not connected/reachable
27    #[error("Sauna is not connected. Check your sauna's network connection.")]
28    SaunaNotConnected,
29
30    /// Invalid parameter value
31    #[error("Invalid parameter: {message}")]
32    InvalidParameter { message: String },
33
34    /// API returned an error
35    #[error("API error: {status_code} - {message}")]
36    ApiError { status_code: u16, message: String },
37
38    /// Network error
39    #[error("Network error: {0}")]
40    Network(#[from] reqwest::Error),
41
42    /// JSON parsing error
43    #[error("Failed to parse response: {0}")]
44    Parse(#[from] serde_json::Error),
45
46    /// Failed to extract verification token
47    #[error("Failed to extract verification token from response")]
48    VerificationTokenNotFound,
49
50    /// Unexpected response format
51    #[error("Unexpected response: {message}")]
52    UnexpectedResponse { message: String },
53}
54
55/// Result type for Klafs operations
56pub type Result<T> = std::result::Result<T, KlafsError>;