pub struct StatusCodeError { /* private fields */ }Expand description
A non-success HTTP response, captured without exposing the response type of the underlying HTTP client.
Status, URL, and headers are available synchronously. The body is not
read up front: the failed response is kept alive and body
streams it on demand, so constructing the error is pure and does no I/O.
Since the response is consumed to read the body, body takes self.
Reading stops at MAX_ERROR_BODY bytes: an error response belongs to the
server, and a hostile or misconfigured one must not be able to make this
allocate an unbounded buffer.
Implementations§
Source§impl StatusCodeError
impl StatusCodeError
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
A header value from the failed response, if present and valid UTF-8.
Sourcepub fn into_response(self) -> Response
pub fn into_response(self) -> Response
Take back the raw failed response for full access to the underlying HTTP client.
This is an opt-in escape hatch: the signature names reqwest::Response,
but only callers who use it need to depend on reqwest. Code that
does not call it is unaffected and can keep using body /
body_text without naming the client crate.
Consumes the error, since a response body can only be read once.
Trait Implementations§
Source§impl Debug for StatusCodeError
impl Debug for StatusCodeError
Source§impl Display for StatusCodeError
impl Display for StatusCodeError
Source§impl Error for StatusCodeError
impl Error for StatusCodeError
1.30.0 · 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()