#[non_exhaustive]pub enum Error {
Unauthorized {
status: u16,
code: Option<String>,
},
Forbidden {
status: u16,
code: Option<String>,
},
RateLimited {
retry_after: Option<Duration>,
},
Http {
status: u16,
code: Option<String>,
message: Option<String>,
},
Decode {
status: u16,
message: String,
snippet: String,
},
Transport(Error),
TooLarge {
limit: usize,
},
Cancelled,
Config(String),
}Expand description
Why a call failed.
No variant holds a token: response bodies are scrubbed (see
Error::Decode) and transport errors drop the URL. Snippets also
drop personal data (emails, names, phone numbers, addresses).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
The token was refused: HTTP 401, or (from the token endpoint) an
invalid_grant, which means the refresh token was revoked or has
already been rotated away. The login needs a new token (a refresh,
or a new login if refreshing gives this too).
Fields
The HTTP status.
The API’s error code, if the body had one (invalid_grant,
authentication_error, permission_error, …).
Forbidden
HTTP 403: the token is good but may not do this (a scope it lacks, such as an inference-only token on a profile endpoint, or a role it lacks in the organization). Logging in again won’t change it.
Fields
RateLimited
HTTP 429.
Fields
Http
Any other non-success status.
Fields
Decode
A success status whose body isn’t the expected JSON.
Fields
Transport(Error)
The request didn’t complete: connect, TLS, a timeout. The error carries no URL.
TooLarge
The response body was larger than the client accepts.
Cancelled
Client::refresh_and_store’s
task was cancelled before it finished (its runtime shut down).
Config(String)
The client was misconfigured (a bad base URL, a header value).
Implementations§
Source§impl Error
impl Error
Whether the login itself is bad (refresh or re-login needed), as
opposed to a passing failure. Not true for Error::Forbidden.
Sourcepub fn is_forbidden(&self) -> bool
pub fn is_forbidden(&self) -> bool
Whether the token was good but not allowed this call
(Error::Forbidden).
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Whether a later retry may succeed: rate limiting, a 5xx, a transport failure.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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()