Skip to main content

Error

Enum Error 

Source
pub enum Error {
Show 20 variants InvalidBaseUrl(ParseError), Transport { kind: TransportKind, message: String, source: Option<Arc<dyn Error + Send + Sync>>, }, Http { status: StatusCode, status_text: String, message: String, body: Option<Bytes>, }, Deserialize { status: StatusCode, message: String, body: Option<Bytes>, }, Timeout, Cancelled, BodyTooLarge { limit: u64, }, MissingBaseUrl, RetryExhausted { attempts: u32, last: Option<Box<Error>>, }, Hook(String), QuerySerialize(String), InvalidHeaderName(String), InvalidHeaderValue(String), MissingPathParam(String), SchemaRoute { method: String, path: String, }, InvalidAuthHeader(String), NonReplayableBody, Io(String), Config(String), Other(String),
}
Expand description

Error type for better-fetch operations.

Variants§

§

InvalidBaseUrl(ParseError)

Base URL parsing failed (ClientBuilder::base_url).

§

Transport

Underlying transport failure (connection, DNS, body read, etc.).

Fields

§kind: TransportKind

Coarse category aligned with reqwest’s is_* helpers.

§message: String

Human-readable detail (typically from the underlying error’s Display).

§source: Option<Arc<dyn Error + Send + Sync>>

Underlying error when available (e.g. reqwest).

§

Http

Non-success HTTP response (when using throw mode or send_json).

Fields

§status: StatusCode

HTTP status code.

§status_text: String

Canonical reason phrase.

§message: String

Human-readable message.

§body: Option<Bytes>

Response body when buffered.

§

Deserialize

JSON response could not be deserialized (feature json).

Fields

§status: StatusCode
§message: String
§

Timeout

Request exceeded the configured timeout.

§

Cancelled

Request was cancelled via CancellationToken.

§

BodyTooLarge

Response body exceeded ClientBuilder::max_response_bytes or a per-request RequestBuilder::max_response_bytes limit on buffered (send / send_json) or streaming responses.

Fields

§limit: u64

Configured maximum response size in bytes.

§

MissingBaseUrl

§

RetryExhausted

Transport retries were exhausted.

Fields

§attempts: u32

Total attempts made (initial + retries).

§last: Option<Box<Error>>

Last error before retries were exhausted, when available.

§

Hook(String)

Returned from on_request or on_response to abort the pipeline. Prefer constructing this with Error::hook rather than Error::Other.

§

QuerySerialize(String)

Query parameter serialization failed (typed endpoint query).

Returned from EndpointRequestBuilder::query and EndpointQuery::apply_query when serde serialization fails (since 0.4.0).

§

InvalidHeaderName(String)

Invalid HTTP header name (RequestBuilder::header).

§

InvalidHeaderValue(String)

Invalid HTTP header value (RequestBuilder::header).

§

MissingPathParam(String)

A :param segment in the path template was not supplied.

§

SchemaRoute

Route not registered in a strict SchemaRegistry (feature schema).

Fields

§method: String

HTTP method.

§path: String

Path template.

§

InvalidAuthHeader(String)

Invalid Authorization header value.

§

NonReplayableBody

Request body cannot be replayed for automatic retry (stream or multipart).

§

Io(String)

I/O error (file writes, etc.).

§

Config(String)

Internal client configuration error.

§

Other(String)

Catch-all for rare plugin errors.

Implementations§

Source§

impl Error

Source

pub fn transport(kind: TransportKind, message: impl Into<String>) -> Error

Builds a transport error with an explicit TransportKind.

Source

pub fn transport_with_source( kind: TransportKind, message: impl Into<String>, source: impl Error + Send + Sync + 'static, ) -> Error

Builds a transport error with an underlying source error.

Source

pub fn transport_message(message: impl Into<String>) -> Error

Builds a transport error with TransportKind::Other.

Source

pub fn transport_source(&self) -> Option<&(dyn Error + Send + Sync)>

Returns the transport error source when present.

Source

pub fn transport_kind(&self) -> Option<TransportKind>

Returns the transport failure category when this error is Error::Transport.

Source

pub fn transport_detail(&self) -> Option<&str>

Returns the transport error detail string when this error is Error::Transport.

Source

pub fn is_transport(&self) -> bool

Returns true when this error is Error::Transport.

Source

pub fn is_timeout(&self) -> bool

Returns true when this error is Error::Timeout.

Source

pub fn http( status: StatusCode, message: impl Into<String>, body: Option<Bytes>, ) -> Error

Builds an HTTP error with canonical status text.

Source

pub fn http_with_status_text( status: StatusCode, status_text: impl Into<String>, message: impl Into<String>, body: Option<Bytes>, ) -> Error

Builds an HTTP error with explicit status text.

Source

pub fn query_serialize(message: impl Into<String>) -> Error

Builds a query serialization error.

Source

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

Returns the HTTP status when this error is response-related.

Source

pub fn status_text(&self) -> Option<&str>

Returns the canonical status text for Error::Http.

Source

pub fn body(&self) -> Option<&Bytes>

Returns the response body when present on HTTP, deserialize, or validation errors.

Source

pub fn is_retry_exhausted(&self) -> bool

Returns true when transport retries were configured but all attempts failed.

Source

pub fn retry_exhausted_last(&self) -> Option<&Error>

Returns the last error from Error::RetryExhausted when present.

Source

pub fn is_cancelled(&self) -> bool

Returns true when the request was cancelled via CancellationToken.

Source

pub fn is_body_too_large(&self) -> bool

Returns true when the response body exceeded a configured size limit.

Source

pub fn body_too_large_limit(&self) -> Option<u64>

Returns the configured byte limit when this error is Error::BodyTooLarge.

Source

pub fn hook(msg: impl Into<String>) -> Error

Builds a hook failure for Hooks::on_request / Hooks::on_response.

Source

pub fn is_hook(&self) -> bool

Returns true when the error is Error::Hook.

Source

pub fn api_json<T>(&self) -> Option<T>

Parses the error response body as JSON (for API error payloads).

§Examples
use better_fetch::Error;
use http::StatusCode;
use serde::Deserialize;

#[derive(Debug, Deserialize, PartialEq)]
struct ApiError {
    message: String,
}

let err = Error::http_with_status_text(
    StatusCode::BAD_REQUEST,
    "Bad Request",
    "bad request",
    Some(bytes::Bytes::from_static(br#"{"message":"invalid"}"#)),
);
let api: ApiError = err.api_json().unwrap();
assert_eq!(api.message, "invalid");

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

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<ParseError> for Error

Source§

fn from(source: ParseError) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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, 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