#[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
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: StatusCodeThe response status.
headers: HeaderMapThe response headers.
body: BytesThe 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: StatusCodeThe 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: HeaderMapThe 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: StringThe decoder’s error message, held as the decoder wrote it; Display escapes its
control characters, since the message may quote server-supplied input.
body: BytesThe retained raw body, capped at max_error_body, except on EventStream’s per-frame
decode, which ClientConfig::max_stream_frame bounds instead.
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
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
status: StatusCodeThe 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.
Implementations§
Source§impl<E> Error<E>
impl<E> Error<E>
Sourcepub fn request_construction(source: impl Error + Send + Sync + 'static) -> Self
pub fn request_construction(source: impl Error + Send + Sync + 'static) -> Self
Build a request-construction error from any owned error value.
Sourcepub fn request_message(message: impl Into<String>) -> Self
pub fn request_message(message: impl Into<String>) -> Self
Build a request-construction error from a static message.
Sourcepub fn is_transient(&self) -> bool
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.
Sourcepub fn status(&self) -> Option<StatusCode>
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.
Sourcepub fn headers(&self) -> Option<&HeaderMap>
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>
impl Error<Infallible>
Source§impl<E: ApiErrorBody> Error<E>
impl<E: ApiErrorBody> Error<E>
Sourcepub fn api_body(&self) -> Option<&E::Body>
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.
Sourcepub fn into_api_body(self) -> Option<E::Body>
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>
impl<E: ApiErrorProblem> Error<E>
Sourcepub fn problem(&self) -> Option<ProblemDetails>
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 throughE’sApiErrorProblem, so it works the same across every status of every operation, whatever body type each one decoded to.Error::DecodeandError::UnexpectedStatuswith a4xxor5xxstatus: the raw body, parsed as JSON. This is how a documented error status whose body did not match its schema — a problemtypethe description does not list — still yields itstypeanddetail. 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: Error + 'static> Error for Error<E>
impl<E: Error + 'static> Error for Error<E>
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<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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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