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
//! Client error types.
use http::StatusCode;
/// Errors that can occur when making client requests.
#[derive(Debug, thiserror::Error)]
pub enum ClientError {
/// The server returned a non-2xx status code.
#[error("request failed with status {status}: {body}")]
Status { status: StatusCode, body: String },
/// Failed to build the request URL.
#[error("invalid URL: {0}")]
Url(#[from] url::ParseError),
/// HTTP transport error.
#[error("request error: {0}")]
Request(#[from] reqwest::Error),
/// Failed to deserialize the response body.
#[error("deserialization error: {0}")]
Deserialize(String),
/// Failed to serialize the request body.
#[error("serialization error: {0}")]
Serialize(String),
/// The request timed out.
#[error("request timed out")]
Timeout,
/// All retry attempts were exhausted.
#[error("all {attempts} retry attempts exhausted: {last_error}")]
RetryExhausted {
/// The error from the final attempt.
last_error: Box<ClientError>,
/// Total number of attempts made (initial + retries).
attempts: u32,
},
}
impl ClientError {
/// Returns `true` if this error represents a timeout.
pub fn is_timeout(&self) -> bool {
match self {
ClientError::Timeout => true,
ClientError::Request(e) => e.is_timeout(),
_ => false,
}
}
}