pub enum Error {
Transport(Error),
Decode(Error),
Api(ApiError),
Unexpected {
status: u16,
body: String,
},
}Expand description
Everything that can go wrong when calling the Messages API.
Variants§
Transport(Error)
The HTTP request never produced a usable response: a connection failure, a timeout, or a request that could not be built or sent. Treated as retryable, since these are usually transient.
Decode(Error)
A 2xx response arrived but its body did not deserialize into the expected shape. Not retried: the same body would fail again.
Api(ApiError)
The API returned a non-2xx response with a well-formed error envelope.
Retryable only for 429, 500, and 529.
Unexpected
A non-2xx response whose body was not a recognizable error envelope. The raw body is preserved so the caller can see what the server actually sent. Not retried.
Implementations§
Source§impl Error
impl Error
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether trying the request again could plausibly succeed.
Transport failures are always worth a retry. API errors are retried for
the three statuses the protocol calls out as transient: 429 (rate
limited), 500 (server error), and 529 (overloaded). Decode failures
and other non-2xx responses are permanent for this request.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
The server-requested wait before retrying, when the response carried a
retry-after header. The retry loop honours this in preference to its
own backoff schedule.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()