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
57
58
59
60
61
62
63
64
65
66
//! Errors retain fixed categories rather than URLs, headers, or native transport chains.
/// A managed HTTP request, body, configuration, or ownership failure.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ClientError {
/// Invalid explicit origin, limits, header policy, or trust root.
Configuration,
/// Ambient TLS root overrides would change the default platform trust policy.
AmbientConfiguration,
/// Managed resource registration failed.
Registration,
/// The requested target is not a relative path within the approved origin.
Destination,
/// The bounded capacity-wait queue is full.
Capacity,
/// The configured capacity-wait allowance expired before the total deadline.
CapacityTimeout,
/// The client has entered managed cleanup or was explicitly closed.
Closed,
/// The original total/inherited request deadline expired.
Deadline,
/// Native connection establishment exceeded its configured limit.
ConnectTimeout,
/// Response/header reads or caller-held body progress exceeded the idle limit.
ReadTimeout,
/// Native transport/protocol failure, without retaining secret-bearing details.
Transport,
/// The supplied request body exceeded the configured byte allowance.
RequestTooLarge,
/// Wire or decoded response-body bytes exceeded the configured allowance.
ResponseTooLarge,
}
impl std::fmt::Display for ClientError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Configuration => "invalid managed HTTP client configuration",
Self::AmbientConfiguration => "ambient TLS root overrides are unsupported",
Self::Registration => "managed HTTP client registration rejected",
Self::Destination => "HTTP destination is outside the approved origin",
Self::Capacity => "HTTP client capacity wait queue is full",
Self::CapacityTimeout => "HTTP client capacity wait allowance expired",
Self::Closed => "HTTP client is closed",
Self::Deadline => "HTTP client operation deadline expired",
Self::ConnectTimeout => "HTTP client connection allowance expired",
Self::ReadTimeout => "HTTP client response progress allowance expired",
Self::Transport => "HTTP client transport failed",
Self::RequestTooLarge => "HTTP client request body exceeds its allowance",
Self::ResponseTooLarge => "HTTP client response body exceeds its allowance",
})
}
}
impl std::error::Error for ClientError {}
impl ClientError {
pub(super) fn transport(error: reqwest::Error) -> Self {
if error.is_timeout() {
if error.is_connect() {
Self::ConnectTimeout
} else {
Self::ReadTimeout
}
} else {
Self::Transport
}
}
}