Struct Error

pub struct Error { /* private fields */ }

The Errors that may occur when processing a Request.

Note: Errors may include the full URL used to make the Request. If the URL contains sensitive information (e.g. an API key as a query parameter), be sure to remove it (without_url)

Implementations

impl Error

fn url(&self) -> Option<&Url>

Returns a possible URL related to this error.

Examples

# async fn run() {
// displays last stop of a redirect loop
let response = reqwest::get("http://site.with.redirect.loop").await;
if let Err(e) = response {
    if e.is_redirect() {
        if let Some(final_stop) = e.url() {
            println!("redirect loop at {final_stop}");
        }
    }
}
# }
fn url_mut(&mut self) -> Option<&mut Url>

Returns a mutable reference to the URL related to this error

This is useful if you need to remove sensitive information from the URL (e.g. an API key in the query), but do not want to remove the URL entirely.

fn with_url(self, url: Url) -> Self

Add a url related to this error (overwriting any existing)

fn without_url(self) -> Self

Strip the related url from this error (if, for example, it contains sensitive information)

fn is_builder(&self) -> bool

Returns true if the error is from a type Builder.

fn is_redirect(&self) -> bool

Returns true if the error is from a RedirectPolicy.

fn is_status(&self) -> bool

Returns true if the error is from Response::error_for_status.

fn is_timeout(&self) -> bool

Returns true if the error is related to a timeout.

fn is_request(&self) -> bool

Returns true if the error is related to the request

fn is_connect(&self) -> bool

Returns true if the error is related to connect

fn is_body(&self) -> bool

Returns true if the error is related to the request or response body

fn is_decode(&self) -> bool

Returns true if the error is related to decoding the response's body

fn status(&self) -> Option<StatusCode>

Returns the status code, if the error was generated from a response.

fn is_upgrade(&self) -> bool

Returns true if the error is related to a protocol upgrade request

Trait Implementations

impl Debug for Error

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Display for Error

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Error for Error

fn source(&self) -> Option<&dyn StdError + 'static>

Auto Trait Implementations

impl !RefUnwindSafe for Error

impl !UnwindSafe for Error

impl Freeze for Error

impl Send for Error

impl Sync for Error

impl Unpin for Error

impl UnsafeUnpin for Error

Blanket Implementations

impl<T> Any for Error where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Error where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Error where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for Error

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Error

impl<T> PolicyExt for Error where T: ?Sized,

fn and<P, B, E>(self, other: P) -> And<T, P>
where
    T: Sized + Policy<B, E>,
    P: Policy<B, E>,
fn or<P, B, E>(self, other: P) -> Or<T, P>
where
    T: Sized + Policy<B, E>,
    P: Policy<B, E>,

impl<T> ToString for Error where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T> WithSubscriber for Error

impl<T, U> Into<U> for Error where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Error where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Error where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>