pub enum Error {
Protocol(Error),
InvalidStatusCodeWithDetails {
status: StatusCode,
body: String,
headers: HeaderMap,
},
InvalidHeaderValue(InvalidHeaderValue),
NoHeaders,
StreamEnded,
InvalidContentType(HeaderValue),
Instance(Box<dyn Error + Send + Sync + 'static>),
}Variants§
Protocol(Error)
InvalidStatusCodeWithDetails
Failed HTTP response preserving its status, body, and headers.
Transport failures without a response use Self::Instance or a
protocol variant.
Fields
status: StatusCodeThe non-success status.
InvalidHeaderValue(InvalidHeaderValue)
NoHeaders
StreamEnded
InvalidContentType(HeaderValue)
Instance(Box<dyn Error + Send + Sync + 'static>)
target_family=wasm only.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.
The following example reads the seconds form of Retry-After:
fn retry_after(error: &Error) -> Option<Duration> {
let seconds = error
.non_success_headers()?
.get(http::header::RETRY_AFTER)?
.to_str()
.ok()?
.parse()
.ok()?;
Some(Duration::from_secs(seconds))
}Returns None for a response-less failure: every non-success error
carries its headers.
Source§impl Error
impl Error
Sourcepub fn instance<E: Error + Send + Sync + 'static>(error: E) -> Self
Available on non-target_family=wasm only.
pub fn instance<E: Error + Send + Sync + 'static>(error: E) -> Self
target_family=wasm only.Wrap a transport’s native error as Error::Instance. Transports use
this for response-less failures (connect, decode, timeout); non-success
responses go through Error::non_success_with_details instead so the
status stays inspectable.
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()