Skip to main content

cloudreve_api/
error.rs

1//! Error types for the Cloudreve API client
2
3use reqwest::Error as ReqwestError;
4use std::io;
5use thiserror::Error;
6
7/// Main error type for the Cloudreve API client
8#[derive(Error, Debug)]
9pub enum Error {
10    /// HTTP request error
11    #[error("HTTP request error: {0}")]
12    Http(#[from] ReqwestError),
13
14    /// JSON serialization/deserialization error
15    #[error("JSON error: {0}")]
16    Json(#[from] serde_json::Error),
17
18    /// IO error
19    #[error("IO error: {0}")]
20    Io(#[from] io::Error),
21
22    /// API error response
23    #[error("API error: {message} (code: {code})")]
24    Api { code: i32, message: String },
25
26    /// Authentication error
27    #[error("Authentication error: {0}")]
28    Auth(String),
29
30    /// Invalid response error
31    #[error("Invalid response: {0}")]
32    InvalidResponse(String),
33
34    /// Invalid timestamp error
35    #[error("Invalid timestamp: {0}")]
36    InvalidTimestamp(String),
37
38    /// Feature not supported in API version
39    #[error("Feature '{0}' not supported in API {1}")]
40    UnsupportedFeature(String, String),
41
42    /// Two-factor authentication required (code: 203)
43    /// Contains the session ID needed for 2FA completion
44    #[error("Two-factor authentication required (session ID: {0})")]
45    TwoFactorRequired(String),
46
47    /// CAPTCHA required for login
48    #[error("CAPTCHA required for login")]
49    CaptchaRequired,
50
51    /// CAPTCHA validation failed
52    #[error("CAPTCHA validation failed: {0}")]
53    CaptchaInvalid(String),
54}