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: HttpErrorKindError category.
method: Option<Method>Optional HTTP method.
url: Option<Url>Optional request URL.
status: Option<StatusCode>Optional response status code.
message: StringHuman-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
impl HttpError
Sourcepub fn new(kind: HttpErrorKind, message: impl Into<String>) -> Self
pub fn new(kind: HttpErrorKind, message: impl Into<String>) -> Self
Sourcepub fn with_method(self, method: Method) -> Self
pub fn with_method(self, method: Method) -> Self
Sourcepub fn with_status(self, status: StatusCode) -> Self
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.
Sourcepub fn with_source<E>(self, source: E) -> Self
pub fn with_source<E>(self, source: E) -> Self
Wraps an underlying error as the HttpError::source chain.
§Parameters
source: Root cause (Send + Sync + 'static).
§Returns
self for chaining.
Sourcepub fn with_response_body_preview(self, preview: impl Into<String>) -> Self
pub fn with_response_body_preview(self, preview: impl Into<String>) -> Self
Sourcepub fn with_retry_after(self, retry_after: Duration) -> Self
pub fn with_retry_after(self, retry_after: Duration) -> Self
Sourcepub fn invalid_url(message: impl Into<String>) -> Self
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.
Sourcepub fn build_client(message: impl Into<String>) -> Self
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.
Sourcepub fn proxy_config(message: impl Into<String>) -> Self
pub fn proxy_config(message: impl Into<String>) -> Self
Builds HttpErrorKind::ProxyConfig.
§Parameters
message: Invalid proxy settings explanation.
§Returns
New HttpError.
Sourcepub fn connect_timeout(message: impl Into<String>) -> Self
pub fn connect_timeout(message: impl Into<String>) -> Self
Sourcepub fn read_timeout(message: impl Into<String>) -> Self
pub fn read_timeout(message: impl Into<String>) -> Self
Sourcepub fn write_timeout(message: impl Into<String>) -> Self
pub fn write_timeout(message: impl Into<String>) -> Self
Sourcepub fn request_timeout(message: impl Into<String>) -> Self
pub fn request_timeout(message: impl Into<String>) -> Self
Builds HttpErrorKind::RequestTimeout.
§Parameters
message: Timeout context for the whole request deadline.
§Returns
New HttpError.
Sourcepub fn transport(message: impl Into<String>) -> Self
pub fn transport(message: impl Into<String>) -> Self
Builds HttpErrorKind::Transport.
§Parameters
message: Low-level I/O or network failure description.
§Returns
New HttpError.
Sourcepub fn status(status: StatusCode, message: impl Into<String>) -> Self
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.
Sourcepub fn decode(message: impl Into<String>) -> Self
pub fn decode(message: impl Into<String>) -> Self
Builds HttpErrorKind::Decode (body or payload decoding).
§Parameters
message: Decode failure description.
§Returns
New HttpError.
Sourcepub fn sse_protocol(message: impl Into<String>) -> Self
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.
Sourcepub fn sse_decode(message: impl Into<String>) -> Self
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.
Sourcepub fn cancelled(message: impl Into<String>) -> Self
pub fn cancelled(message: impl Into<String>) -> Self
Builds HttpErrorKind::Cancelled.
§Parameters
message: Why the operation was cancelled.
§Returns
New HttpError.
Sourcepub fn retry_hint(&self) -> RetryHint
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 Error for HttpError
impl Error for HttpError
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()
Auto Trait Implementations§
impl Freeze for HttpError
impl !RefUnwindSafe for HttpError
impl Send for HttpError
impl Sync for HttpError
impl Unpin for HttpError
impl UnsafeUnpin for HttpError
impl !UnwindSafe for HttpError
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
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.