Skip to main content

cyberdrop_client/
error.rs

1use reqwest::StatusCode;
2use thiserror::Error;
3
4/// Errors returned by this crate.
5///
6/// This type includes HTTP status classification (authentication vs other failures), conversion
7/// errors from loosely-typed API responses, and underlying I/O / HTTP client errors.
8///
9/// Notes:
10/// - Network/transport failures (including timeouts) are returned as [`CyberdropError::Http`].
11/// - Many API responses contain optional fields; missing required fields are reported as
12///   [`CyberdropError::MissingField`].
13#[derive(Debug, Error)]
14pub enum CyberdropError {
15    /// An invalid URL was provided or returned.
16    #[error("invalid url: {0}")]
17    InvalidUrl(#[from] url::ParseError),
18    /// The server returned `401 Unauthorized` or `403 Forbidden`.
19    #[error("authentication failed with status {0}")]
20    AuthenticationFailed(StatusCode),
21    /// A request completed but returned a non-success HTTP status (other than `401`/`403`).
22    #[error("request failed with status {0}")]
23    RequestFailed(StatusCode),
24    /// An endpoint requiring authentication was called without configuring a token.
25    #[error("auth token required for this request")]
26    MissingAuthToken,
27    /// The login response did not include a token.
28    #[error("response missing token")]
29    MissingToken,
30    /// A required field was missing in an API response body.
31    #[error("{0}")]
32    MissingField(&'static str),
33    /// The service indicates an album already exists (as interpreted by this crate).
34    #[error("folder already present: {0}")]
35    AlbumAlreadyExists(String),
36    /// Requested album ID was not present in the authenticated user's album list.
37    #[error("album not found: {0}")]
38    AlbumNotFound(u64),
39    /// The API returned an error message or an unexpected response shape.
40    #[error("api error: {0}")]
41    Api(String),
42    /// The provided file path did not yield a valid UTF-8 file name.
43    #[error("invalid file name")]
44    InvalidFileName,
45    /// An underlying I/O operation failed.
46    #[error("io error: {0}")]
47    Io(#[from] std::io::Error),
48    /// An underlying HTTP client operation failed.
49    #[error(transparent)]
50    Http(#[from] reqwest::Error),
51}