Skip to main content

typeway_client/
error.rs

1//! Client error types.
2
3use http::StatusCode;
4
5/// Errors that can occur when making client requests.
6#[derive(Debug, thiserror::Error)]
7pub enum ClientError {
8    /// The server returned a non-2xx status code.
9    #[error("request failed with status {status}: {body}")]
10    Status { status: StatusCode, body: String },
11
12    /// Failed to build the request URL.
13    #[error("invalid URL: {0}")]
14    Url(#[from] url::ParseError),
15
16    /// HTTP transport error.
17    #[error("request error: {0}")]
18    Request(#[from] reqwest::Error),
19
20    /// Failed to deserialize the response body.
21    #[error("deserialization error: {0}")]
22    Deserialize(String),
23
24    /// Failed to serialize the request body.
25    #[error("serialization error: {0}")]
26    Serialize(String),
27
28    /// The request timed out.
29    #[error("request timed out")]
30    Timeout,
31
32    /// All retry attempts were exhausted.
33    #[error("all {attempts} retry attempts exhausted: {last_error}")]
34    RetryExhausted {
35        /// The error from the final attempt.
36        last_error: Box<ClientError>,
37        /// Total number of attempts made (initial + retries).
38        attempts: u32,
39    },
40}
41
42impl ClientError {
43    /// Returns `true` if this error represents a timeout.
44    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}