Skip to main content

HttpError

Struct HttpError 

Source
pub struct HttpError {
    pub kind: HttpErrorKind,
    pub method: Option<Method>,
    pub url: Option<Url>,
    pub status: Option<StatusCode>,
    pub message: String,
    pub response_body_preview: Option<String>,
    pub retry_after: Option<Duration>,
    pub source: Option<BoxError>,
}
Expand description

Unified HTTP error type.

Fields§

§kind: HttpErrorKind

Error category.

§method: Option<Method>

Optional HTTP method.

§url: Option<Url>

Optional request URL.

§status: Option<StatusCode>

Optional response status code.

§message: String

Human-readable message.

§response_body_preview: Option<String>

Optional preview of non-success response body.

§retry_after: Option<Duration>

Optional Retry-After duration parsed from a non-success response.

§source: Option<BoxError>

Optional source error.

Implementations§

Source§

impl HttpError

Source

pub fn new(kind: HttpErrorKind, message: impl Into<String>) -> Self

Creates an error with kind and message; other fields are unset until chained.

§Parameters
  • kind: Classification for retry logic and handling.
  • message: Human-readable description.
§Returns

New HttpError.

Source

pub fn with_method(self, method: Method) -> Self

Attaches the HTTP method for diagnostics.

§Parameters
  • method: Request method associated with the failure.
§Returns

self for chaining.

Source

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

Attaches the request URL for diagnostics.

§Parameters
  • url: Request URL associated with the failure.
§Returns

self for chaining.

Source

pub fn with_status(self, status: StatusCode) -> Self

Attaches an HTTP status code (e.g. for HttpErrorKind::Status).

§Parameters
  • status: Response status code.
§Returns

self for chaining.

Source

pub fn with_source<E>(self, source: E) -> Self
where E: Error + Send + Sync + 'static,

Wraps an underlying error as the HttpError::source chain.

§Parameters
  • source: Root cause (Send + Sync + 'static).
§Returns

self for chaining.

Source

pub fn with_response_body_preview(self, preview: impl Into<String>) -> Self

Attaches a preview of the non-success response body.

§Parameters
  • preview: Truncated or summarized response body text.
§Returns

self for chaining.

Source

pub fn with_retry_after(self, retry_after: Duration) -> Self

Attaches parsed Retry-After duration from a non-success response.

§Parameters
  • retry_after: Parsed retry delay.
§Returns

self for chaining.

Source

pub fn invalid_url(message: impl Into<String>) -> Self

Builds HttpErrorKind::InvalidUrl.

§Parameters
  • message: Why the URL is invalid or cannot be resolved.
§Returns

New HttpError.

Source

pub fn build_client(message: impl Into<String>) -> Self

Builds HttpErrorKind::BuildClient (e.g. reqwest builder failure).

§Parameters
  • message: Build failure description.
§Returns

New HttpError.

Source

pub fn proxy_config(message: impl Into<String>) -> Self

Builds HttpErrorKind::ProxyConfig.

§Parameters
  • message: Invalid proxy settings explanation.
§Returns

New HttpError.

Source

pub fn connect_timeout(message: impl Into<String>) -> Self

Builds HttpErrorKind::ConnectTimeout.

§Parameters
  • message: Timeout context.
§Returns

New HttpError.

Source

pub fn read_timeout(message: impl Into<String>) -> Self

Builds HttpErrorKind::ReadTimeout.

§Parameters
  • message: Timeout context.
§Returns

New HttpError.

Source

pub fn write_timeout(message: impl Into<String>) -> Self

Builds HttpErrorKind::WriteTimeout.

§Parameters
  • message: Timeout context.
§Returns

New HttpError.

Source

pub fn request_timeout(message: impl Into<String>) -> Self

Builds HttpErrorKind::RequestTimeout.

§Parameters
  • message: Timeout context for the whole request deadline.
§Returns

New HttpError.

Source

pub fn transport(message: impl Into<String>) -> Self

Builds HttpErrorKind::Transport.

§Parameters
  • message: Low-level I/O or network failure description.
§Returns

New HttpError.

Source

pub fn status(status: StatusCode, message: impl Into<String>) -> Self

Builds HttpErrorKind::Status with the given status pre-filled.

§Parameters
  • status: HTTP status from the response.
  • message: Additional context.
§Returns

New HttpError with HttpError::status set.

Source

pub fn decode(message: impl Into<String>) -> Self

Builds HttpErrorKind::Decode (body or payload decoding).

§Parameters
  • message: Decode failure description.
§Returns

New HttpError.

Source

pub fn sse_protocol(message: impl Into<String>) -> Self

Builds HttpErrorKind::SseProtocol (framing, UTF-8, SSE line rules).

§Parameters
  • message: Protocol violation description.
§Returns

New HttpError.

Source

pub fn sse_decode(message: impl Into<String>) -> Self

Builds HttpErrorKind::SseDecode (e.g. JSON in SSE data).

§Parameters
  • message: Payload decode failure description.
§Returns

New HttpError.

Source

pub fn cancelled(message: impl Into<String>) -> Self

Builds HttpErrorKind::Cancelled.

§Parameters
  • message: Why the operation was cancelled.
§Returns

New HttpError.

Source

pub fn other(message: impl Into<String>) -> Self

Builds HttpErrorKind::Other.

§Parameters
  • message: Catch-all description.
§Returns

New HttpError.

Source

pub fn retry_hint(&self) -> RetryHint

Classifies this error for retry policies (RetryHint).

§Returns

RetryHint::Retryable for timeouts, transport errors, and some HTTP statuses; otherwise non-retryable.

Trait Implementations§

Source§

impl Debug for HttpError

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for HttpError

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Error for HttpError

Source§

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

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for HttpError

Source§

fn from(error: Error) -> Self

Maps std::io::Error to HttpError::transport with the I/O error as source.

§Parameters
  • error: Underlying I/O error.
§Returns

Wrapped HttpError.

Source§

impl From<Error> for HttpError

Source§

fn from(error: Error) -> Self

Maps reqwest::Error to HttpErrorKind::BuildClient with chained source.

§Parameters
  • error: Reqwest error to wrap.
§Returns

Wrapped HttpError.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

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

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

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

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

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

ToString::to_string, but without panic on OOM.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more