#[non_exhaustive]pub enum Error {
Protocol(Error),
InvalidStatusCodeWithDetails {
status: StatusCode,
body: String,
headers: HeaderMap,
},
StreamEnded,
InvalidContentType(HeaderValue),
Transient(BoxError),
Permanent(BoxError),
}Expand description
Why an HTTP request failed: a protocol or header error, a non-success reply, or the transport’s own error, which says whether sending the same request again may work.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Protocol(Error)
The request could not be built.
InvalidStatusCodeWithDetails
Failed HTTP response preserving its status, body, and headers.
Transport failures without a response use Self::Transient,
Self::Permanent or a protocol variant.
Fields
status: StatusCodeThe non-success status.
StreamEnded
The response stream ended before it was done.
InvalidContentType(HeaderValue)
The response’s content type was not the one expected.
Transient(BoxError)
The transport failed without a reply, and sending the same request again may work: a refused or reset connection, a timeout, a body cut short.
Permanent(BoxError)
The transport failed without a reply, and sending the same request again fails the same way: a request it cannot send as it is, missing credentials, a client that could not be built.
Implementations§
Source§impl Error
impl Error
Sourcepub fn non_success_status(&self) -> Option<StatusCode>
pub fn non_success_status(&self) -> Option<StatusCode>
Preserved HTTP failure status, or None for other error variants.
Sourcepub fn non_success_body(&self) -> Option<&str>
pub fn non_success_body(&self) -> Option<&str>
The response body this error preserved, when it has one. Companion to
Self::non_success_status and Self::non_success_headers.
Sourcepub fn non_success_with_details(
status: StatusCode,
headers: HeaderMap,
body: String,
) -> Self
pub fn non_success_with_details( status: StatusCode, headers: HeaderMap, body: String, ) -> Self
Constructs a failure from its HTTP status, headers, and body without validating that the status is non-successful.
Sourcepub fn non_success_headers(&self) -> Option<&HeaderMap>
pub fn non_success_headers(&self) -> Option<&HeaderMap>
Returns the failed response’s headers, when this error preserved them.
Don’t parse Retry-After from them by hand: a provider error carries
these headers into rig-core’s ErrorReport, whose retry_after reads
every form of the wait a provider asks for.
Returns None for a response-less failure: every non-success error
carries its headers.
Source§impl Error
impl Error
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Whether sending the same request again may pass: after StreamEnded
and what the transport called Error::Transient it may, a status
decides through retryable_status, and after anything else
(protocol, header and content-type errors, Error::Permanent) it
does not. A retry may repeat a request the server already processed.
Sourcepub fn transient(error: impl Into<BoxError>) -> Self
pub fn transient(error: impl Into<BoxError>) -> Self
A transport’s own error after which sending the same request again
may work, such as a reset connection or a timeout. A non-success
reply goes through Error::non_success_with_details instead, so its
status decides.
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()