1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/// Error type for the TMDB provider.
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum TmdbError {
/// Error from the underlying HTTP client.
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
/// Error from the progenitor-generated client, with the HTTP status code.
///
/// The `status` field carries the HTTP response code (e.g. 401, 404) so
/// callers can distinguish authentication failures from missing resources
/// without parsing the message string.
#[error("API error {status}: {message}")]
Api {
/// HTTP response status code.
status: u16,
/// Human-readable error description from the API or client library.
message: String,
},
/// JSON deserialization error.
#[error("deserialization error: {0}")]
Deserialization(#[from] serde_json::Error),
/// Exceeded the configured per-client request concurrency timeout.
///
/// Raised when `TmdbConfig::rate_limit_timeout` is set and a semaphore
/// permit could not be acquired within that duration, indicating that all
/// concurrent request slots are occupied.
#[error("rate limit exceeded: no permit available within timeout")]
RateLimitExceeded,
/// The rate-limit semaphore has been closed (internal error).
///
/// This should not occur in normal operation; it indicates that the
/// internal concurrency semaphore was unexpectedly dropped.
#[error("internal error: rate-limit semaphore closed")]
Closed,
/// Invalid configuration.
#[error("invalid configuration: {0}")]
InvalidConfig(String),
}
impl<T: std::fmt::Debug + Send + Sync + 'static> From<progenitor_client::Error<T>> for TmdbError {
fn from(err: progenitor_client::Error<T>) -> Self {
// `progenitor_client::Error::status()` returns `Option<reqwest::StatusCode>`,
// covering both `ErrorResponse` and `UnexpectedResponse` variants.
let status = err.status().map(|s| s.as_u16()).unwrap_or(0);
TmdbError::Api {
status,
message: format!("{err}"),
}
}
}