pub struct ErrorWithBody { /* private fields */ }Expand description
A reqwest::Error that may also contain the response body.
Created from a response using the
ResponseExt::error_for_status_with_body method. Can also be created from
a reqwest::Error.
§Example
use reqwest_extra::{ErrorWithBody, ResponseExt};
async fn fetch_string(url: &str) -> Result<String, ErrorWithBody> {
let response = reqwest::get(url)
.await?
.error_for_status_with_body()
.await?
.text()
.await?;
Ok(response)
}
let err = fetch_string("https://api.github.com/user").await.unwrap_err();
println!("{err}");Output (line-wrapped for readability):
HTTP status client error (403 Forbidden) for url (https://api.github.com/user),
body: b"\r\nRequest forbidden by administrative rules.
Please make sure your request has a User-Agent header
(https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required).
Check https://developer.github.com for other possible causes.\r\n"Implementations§
Source§impl ErrorWithBody
impl ErrorWithBody
Sourcepub fn inner(&self) -> &Error
pub fn inner(&self) -> &Error
Get a reference to the inner reqwest::Error.
Sourcepub fn into_inner(self) -> Error
pub fn into_inner(self) -> Error
Consume the ErrorWithBody, returning the inner reqwest::Error.
Sourcepub fn body(&self) -> Option<&Result<Bytes, Error>>
pub fn body(&self) -> Option<&Result<Bytes, Error>>
Get a reference to the response body, if available.
Sourcepub fn into_body(self) -> Option<Result<Bytes, Error>>
pub fn into_body(self) -> Option<Result<Bytes, Error>>
Consume the ErrorWithBody, returning the response body, if available.
Sourcepub fn into_parts(self) -> (Error, Option<Result<Bytes, Error>>)
pub fn into_parts(self) -> (Error, Option<Result<Bytes, Error>>)
Consume the ErrorWithBody, returning both the inner reqwest::Error
and the response body, if available.
Trait Implementations§
Source§impl Debug for ErrorWithBody
impl Debug for ErrorWithBody
Source§impl Display for ErrorWithBody
impl Display for ErrorWithBody
Source§impl Error for ErrorWithBody
impl Error for ErrorWithBody
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl !Freeze for ErrorWithBody
impl !RefUnwindSafe for ErrorWithBody
impl Send for ErrorWithBody
impl Sync for ErrorWithBody
impl Unpin for ErrorWithBody
impl !UnwindSafe for ErrorWithBody
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.