Skip to main content

qobuz_api/
errors.rs

1//! Error types for the Qobuz API client.
2
3#[cfg(test)]
4pub mod diagnostics;
5
6use std::io::Error as IoError;
7
8use {reqwest::Error as ReqwestError, thiserror::Error};
9
10/// Error type for all Qobuz API operations.
11///
12/// Implements `Send + Sync + 'static` for use in async Tokio tasks.
13#[derive(Error, Debug)]
14pub enum QobuzApiError {
15    /// Authentication failure (invalid credentials, expired tokens).
16    #[error("Authentication failed: {message}")]
17    AuthenticationError {
18        /// Error description.
19        message: String,
20    },
21
22    /// HTTP request failure (network, timeout).
23    #[error("HTTP request failed: {0}")]
24    HttpError(#[from] ReqwestError),
25
26    /// I/O failure (file system, permissions).
27    #[error("I/O error: {0}")]
28    IoError(#[from] IoError),
29
30    /// API returned an error response with code and message.
31    #[error("API error {code}: {message}")]
32    ApiErrorResponse {
33        /// API error code.
34        code: i32,
35        /// API error message.
36        message: String,
37        /// API error status.
38        status: String,
39    },
40
41    /// Failed to parse the API response body.
42    #[error("Failed to parse API response: {content}")]
43    ApiResponseParseError {
44        /// The content that failed to parse.
45        content: String,
46        /// Optional source of the parse failure.
47        source_info: Option<String>,
48    },
49
50    /// Service initialization failure.
51    #[error("Service initialization failed: {message}")]
52    InitializationError {
53        /// Error description.
54        message: String,
55    },
56
57    /// Invalid or missing credentials.
58    #[error("Invalid credentials: {message}")]
59    CredentialsError {
60        /// Error description.
61        message: String,
62    },
63
64    /// Download failure (file creation, network, disk).
65    #[error("Download failed: {message}")]
66    DownloadError {
67        /// Error description.
68        message: String,
69    },
70
71    /// Metadata tagging failure.
72    #[error("Metadata error: {0}")]
73    MetadataError(String),
74
75    /// Requested resource not found by ID.
76    #[error("{resource_type} not found: {resource_id}")]
77    ResourceNotFoundError {
78        /// Type of resource (album, artist, track, playlist).
79        resource_type: String,
80        /// Identifier that was not found.
81        resource_id: String,
82    },
83
84    /// Rate limited by the API (retries exhausted).
85    #[error("Rate limited: {message}")]
86    RateLimitError {
87        /// Error description.
88        message: String,
89    },
90
91    /// Invalid parameter passed to an API method.
92    #[error("Invalid parameter: {message}")]
93    InvalidParameterError {
94        /// Error description.
95        message: String,
96    },
97
98    /// Unexpected API response structure or content.
99    #[error("Unexpected API response: {message}")]
100    UnexpectedApiResponseError {
101        /// Error description.
102        message: String,
103    },
104
105    /// Download was cancelled by the user.
106    #[error("Download cancelled")]
107    Canceled,
108}