Struct Error

struct Error { ... }

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: &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(self: &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: Self, url: Url) -> Self

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

fn without_url(self: Self) -> Self

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

fn is_builder(self: &Self) -> bool

Returns true if the error is from a type Builder.

fn is_redirect(self: &Self) -> bool

Returns true if the error is from a RedirectPolicy.

fn is_status(self: &Self) -> bool

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

fn is_timeout(self: &Self) -> bool

Returns true if the error is related to a timeout.

fn is_request(self: &Self) -> bool

Returns true if the error is related to the request

fn is_connect(self: &Self) -> bool

Returns true if the error is related to connect

fn is_body(self: &Self) -> bool

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

fn is_decode(self: &Self) -> bool

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

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

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

fn is_upgrade(self: &Self) -> bool

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

impl Debug for Error

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

impl Display for Error

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

impl Error for Error

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

impl Freeze for Error

impl RefUnwindSafe for Error

impl Send for Error

impl Sync for Error

impl Unpin for Error

impl UnsafeUnpin for Error

impl UnwindSafe for Error

impl<T> Any for Error

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Error

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Error

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

impl<T> ErasedDestructor for Error

impl<T> From for Error

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Error

impl<T> PolicyExt for Error

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

impl<T> ToString for Error

fn to_string(self: &Self) -> String

impl<T> ToStringFallible for Error

fn try_to_string(self: &Self) -> Result<String, TryReserveError>

[ToString::to_string]alloc::string::ToString::to_string, but without panic on OOM.

impl<T> WithSubscriber for Error

impl<T, U> Into for Error

fn into(self: 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 for Error

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Error

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