1use http::StatusCode;
4
5#[derive(Debug, thiserror::Error)]
7pub enum ClientError {
8 #[error("request failed with status {status}: {body}")]
10 Status { status: StatusCode, body: String },
11
12 #[error("invalid URL: {0}")]
14 Url(#[from] url::ParseError),
15
16 #[error("request error: {0}")]
18 Request(#[from] reqwest::Error),
19
20 #[error("deserialization error: {0}")]
22 Deserialize(String),
23
24 #[error("serialization error: {0}")]
26 Serialize(String),
27
28 #[error("request timed out")]
30 Timeout,
31
32 #[error("all {attempts} retry attempts exhausted: {last_error}")]
34 RetryExhausted {
35 last_error: Box<ClientError>,
37 attempts: u32,
39 },
40}
41
42impl ClientError {
43 pub fn is_timeout(&self) -> bool {
45 match self {
46 ClientError::Timeout => true,
47 ClientError::Request(e) => e.is_timeout(),
48 _ => false,
49 }
50 }
51}