Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error<E> { RequestConstruction(RequestError), Transport(TransportError), Timeout(TimeoutKind), Protocol(ProtocolError), Redirect(RedirectError), Api(ResponseValue<E>), UnexpectedStatus { status: StatusCode, headers: HeaderMap, body: Bytes, }, Decode { status: StatusCode, headers: HeaderMap, path: String, body: Bytes, truncated: bool, }, InterruptedBody(TransportError), PaginationCycle { url: Url, }, BodyTooLarge { limit: usize, status: StatusCode, }, PaginationOriginChanged { from: Url, to: Url, }, }
Expand description

The closed error taxonomy shared by every spargen-generated client. E is the operation’s typed error body (an enum when several error statuses are documented).

Twelve variants are constructed: classes #1 to #9, and #11 to #13. Taxonomy class #10, cancellation, is a documented drop-safety guarantee rather than a variant: dropping a returned future is safe and side-effect-free beyond standard HTTP semantics. The enum implements std::error::Error, whose source() reaches each retained cause; each level of that chain displays only its own text, so a reporter that prints the whole chain prints each cause once.

Debug prints the response headers of Error::Api, Error::UnexpectedStatus and Error::Decode with the value of every Set-Cookie, Authorization and Proxy-Authenticate header, and of every header whose value is marked sensitive, replaced by [redacted]; header names, every other header, the status and the body print as they are.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

RequestConstruction(RequestError)

#1 — a request could not be built, or failed inside the send before that request produced a response. Read it as a statement about one request, not about the operation: it is neither proof that nothing reached the server, nor proof that no response was already produced and delivered to the caller.

RequestError types the four credential causes, each raised before anything is sent; every other cause arrives as RequestError::Other, whose documentation says which of them are raised before anything is sent and which are not. Read it before retrying.

§

Transport(TransportError)

#2 — DNS failure, connection refused/reset, TLS handshake or certificate error.

§

Timeout(TimeoutKind)

#3 — connect vs total-request timeout (as configured on the injected client).

§

Protocol(ProtocolError)

#4 — malformed HTTP or decompression failure. On native targets, a response body the connection cut short is not this class but Error::InterruptedBody; on wasm32, a non-streamed one is this class, as Error::InterruptedBody describes.

§

Redirect(RedirectError)

#5 — a redirect not followed: the default backend refuses one to another origin (RedirectError::cross_origin_target) or past ten hops; an injected client or backend reports one as its own policy decides.

§

Api(ResponseValue<E>)

#6 — a documented non-success status parsed into the operation’s typed error body.

§

UnexpectedStatus

#7 — an undocumented status; the raw body is preserved for forensics.

Fields

§status: StatusCode

The response status.

§headers: HeaderMap

The response headers.

§body: Bytes

The raw response body, capped as ClientConfig::max_error_body documents.

§

Decode

#8 — the response body failed to deserialize; retains the status and headers the response carried, the decoder’s error message, and the raw body, capped on every path but the one named on body below. A documented error status whose body does not match its schema (a problem type the description does not list, or an HTML page from a proxy in front of the server) arrives here with its status and headers intact, so the caller can still act on them — honour a Retry-After on a 429, say.

Fields

§status: StatusCode

The status of the response whose body failed to decode: a success status when a success body did not match its schema, the documented error status when a documented error body did not. For EventStream’s per-frame decode, it is the status of the response the frame was read from — after a reconnect, the reconnected response’s.

§headers: HeaderMap

The headers of the response whose body failed to decode — for EventStream’s per-frame decode, of the response the frame was read from, as for status.

§path: String

The decoder’s error message, held as the decoder wrote it; Display escapes its control characters, since the message may quote server-supplied input.

§body: Bytes

The retained raw body, capped at max_error_body, except on EventStream’s per-frame decode, which ClientConfig::max_stream_frame bounds instead.

§truncated: bool

Whether bytes were dropped from body to meet a cap: false means nothing was dropped.

§

InterruptedBody(TransportError)

#9 — the connection dropped partway through a response body: mid-stream on a streamed response, or, on native targets, while any other response body, success or error, was being read. On wasm32, the fetch backend reports a non-streamed body that fails to read as a JavaScript error, which carries no evidence that the connection gave out, so that failure is Error::Protocol there.

§

PaginationCycle

#11 — a LinkPaginator page’s rel="next" link named a URL the paginator had already fetched (a self-link, or a longer cycle such as page 1 → page 2 → page 1), so following it would never end. Every page before it was yielded; nothing was sent for url.

Fields

§url: Url

The revisited URL the next link resolved to, without its userinfo and query, where a credential would ride.

§

BodyTooLarge

#12 — a non-streaming operation’s response body exceeded the limit the call was made under: super::RequestOptions::max_body, or for a success body ClientConfig::max_success_body, and for a raw binary success body where neither is set ClientConfig::DEFAULT_MAX_BINARY_BODY; or the limit a super::ByteStream’s collect_bounded was given. A Content-Length past it is refused before the body is read, unless the response carries no body (a HEAD request’s answer, or a 1xx, 204 or 304); a body that grows past it is abandoned at the chunk that crosses it. Nothing of the body is retained. Not transient: the same limit refuses the same response again.

Fields

§limit: usize

The limit, in bytes, the body exceeded.

§status: StatusCode

The status of the response whose body exceeded it.

§

PaginationOriginChanged

#13 — a LinkPaginator page’s rel="next" link named a URL whose scheme, host or port differs from the first page the paginator fetched: another host, another port, or an https chain dropping to http. Following it would send whatever the injected client attaches to every request (a default Authorization header, say) to that origin. Every page before it was yielded; nothing was sent for to. Not transient: the same link is refused again.

Fields

§from: Url

The first page the paginator fetched, whose origin every later page must share, without its userinfo and query, where a credential would ride.

§to: Url

The refused URL the next link resolved to, without its userinfo and query.

Implementations§

Source§

impl<E> Error<E>

Source

pub fn request_construction(source: impl Error + Send + Sync + 'static) -> Self

Build a request-construction error from any owned error value.

Source

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

Build a request-construction error from a static message.

Source

pub fn is_transient(&self) -> bool

Whether the failure is worth retrying: transport failures, timeouts, and a 429 or 5xx response — whichever class carries it, including Error::Decode, since a server that answered 503 is unavailable whether or not its body matched the schema. This is the rule RetryOutcome::is_transient applies to the undecoded response of an idempotent request. This classifies the failure alone: whether re-sending the request is safe also depends on its method, which RetryOutcome::is_idempotent reads.

Source

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

The HTTP status the failed call’s response carried: Some for a documented error status (Error::Api, the same value as its ResponseValue::status()), for an undocumented status (Error::UnexpectedStatus, which includes an undocumented 2xx), and for a response whose body failed to decode (Error::Decode, success or documented error status alike), and for a response whose body exceeded its limit (Error::BodyTooLarge); None for every class that produced no response to read a status from.

Source

pub fn headers(&self) -> Option<&HeaderMap>

The headers of the response the failed call received: Some for Error::Api (the same map as its ResponseValue::headers()), Error::UnexpectedStatus, and Error::Decode, and None for every other class: those that produced no response, and Error::BodyTooLarge, which keeps its response’s status alone. A Retry-After on a 429 or 503 is read here whichever of those classes carried it.

Source§

impl Error<Infallible>

Source

pub fn widen<E>(self) -> Error<E>

Widen a never-typed failure into any operation’s error type. Dispatch routines that cannot produce a typed API error return Error<Infallible>; generated shims widen at the call site via .map_err(Error::widen).

Source§

impl<E: ApiErrorBody> Error<E>

Source

pub fn api_body(&self) -> Option<&E::Body>

The documented API error body, whichever status carried it: Some only for Error::Api whose E reports a body. Its status is Error::status, the same value as the ResponseValue::status() inside Api.

Source

pub fn into_api_body(self) -> Option<E::Body>

The documented API error body, moved out of the error: Some exactly when Error::api_body is, for the same body. Read Error::status and Error::headers first where they are wanted too, since this consumes the error.

Source§

impl<E: ApiErrorProblem> Error<E>

Source

pub fn problem(&self) -> Option<ProblemDetails>

The RFC 9457 problem-details members of the failed call’s error response body, from whichever class carried one.

  • Error::Api: the documented body, read through E’s ApiErrorProblem, so it works the same across every status of every operation, whatever body type each one decoded to.
  • Error::Decode and Error::UnexpectedStatus with a 4xx or 5xx status: the raw body, parsed as JSON. This is how a documented error status whose body did not match its schema — a problem type the description does not list — still yields its type and detail. A success status is not read: its body was never an error response.
  • Every other class produced no response body, and answers None.

Trait Implementations§

Source§

impl<E: Debug> Debug for Error<E>

Source§

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

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

impl<E: Display> Display for Error<E>

Source§

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

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

impl<E: Error + 'static> Error for Error<E>

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

Auto Trait Implementations§

§

impl<E> !Freeze for Error<E>

§

impl<E> !RefUnwindSafe for Error<E>

§

impl<E> !UnwindSafe for Error<E>

§

impl<E> Send for Error<E>
where E: Send,

§

impl<E> Sync for Error<E>
where E: Sync,

§

impl<E> Unpin for Error<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for Error<E>
where E: UnsafeUnpin,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self> ⓘ

Get a clone of the Arc<> using a “borrowed” handle. Read more
§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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