#[non_exhaustive]pub enum Class {
Network,
Unavailable {
code: Option<Arc<str>>,
},
RateLimited {
retry_after: Option<Duration>,
},
Unauthorized,
InvalidRequest,
VenueRefusal {
code: Option<Arc<str>>,
},
Restricted,
Decode,
}Expand description
What kind of failure an error is, whichever venue or transport produced it.
A caller decides whether to retry, back off, alert or give up from the
class alone, so one policy serves every crate. An HTTP status decides the
class before any body does (see class_for_status).
code fields hold the venue’s own error code, never the HTTP status, with
numeric codes written in decimal.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Network
No response arrived: a failed connect, a timeout, a reset, a TLS EOF, a DNS failure, or a socket that closed.
The host is unwell or busy: a 408, 425 or 5xx, whatever the body says.
RateLimited
A 429.
A 401 or 403: the credentials were missing, wrong or not allowed.
InvalidRequest
The client refused the request itself, or was misused: local validation, a bad URL, a socket used after it closed. No status ever produces it.
VenueRefusal
The venue refused the request: any 4xx without a class of its own, or a socket closed with a protocol or application close code.
Restricted
The venue will not serve this caller: a 418 ban, a 451 region block, or a firewall refusal a venue documents as one.
Decode
A successful response, or a frame, that did not parse.
Implementations§
Source§impl Class
impl Class
Sourcepub fn is_retriable(&self) -> bool
pub fn is_retriable(&self) -> bool
Whether retrying could plausibly succeed: true for
Network, Unavailable and
RateLimited.
This describes the failure, not the operation. A retriable error on an order placement still needs the caller to judge whether resubmitting is safe.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
The wait a RateLimited class carries, and None
for every other class and for a zero wait.
Sourcepub fn code(&self) -> Option<&str>
pub fn code(&self) -> Option<&str>
The venue’s code, for Unavailable and
VenueRefusal.
Sourcepub fn with_code(self, code: impl Into<Arc<str>>) -> Self
pub fn with_code(self, code: impl Into<Arc<str>>) -> Self
Sets the venue’s code on Unavailable and
VenueRefusal. Every other class is returned
unchanged, since it has nowhere to put one.
Sourcepub fn with_retry_after(self, retry_after: Option<Duration>) -> Self
pub fn with_retry_after(self, retry_after: Option<Duration>) -> Self
Sets the wait on RateLimited. A zero wait is
dropped, since it asks for nothing. Every other class is returned
unchanged.