pub struct Error { /* private fields */ }Expand description
The error every SDK call can answer with.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(code: ErrorCode, message: impl Into<String>) -> Error
pub fn new(code: ErrorCode, message: impl Into<String>) -> Error
An error of a category, with a message.
Sourcepub fn usage_with_hint(
message: impl Into<String>,
hint: impl Into<String>,
) -> Error
pub fn usage_with_hint( message: impl Into<String>, hint: impl Into<String>, ) -> Error
The call was built wrong, and here is what to do about it.
Sourcepub fn not_found(resource: &str, identifier: impl Display) -> Error
pub fn not_found(resource: &str, identifier: impl Display) -> Error
A record that is not there.
Sourcepub fn forbidden_scope() -> Error
pub fn forbidden_scope() -> Error
Access denied for want of scope, as a write answered 403 usually is.
Sourcepub fn rate_limit(retry_after: Option<u64>) -> Error
pub fn rate_limit(retry_after: Option<u64>) -> Error
The rate-limit error a caller raises for itself, worded the way the other SDKs word
theirs: “Rate limited”. A 429 that came back from Fizzy reads “rate limited - try
again later” instead — see Error::from_response.
Sourcepub fn rate_limited() -> Error
pub fn rate_limited() -> Error
The client’s own rate limiter refused a call, so nothing was sent.
Sourcepub fn circuit_open() -> Error
pub fn circuit_open() -> Error
The scope’s circuit breaker is open, so the SDK refused the call itself.
Sourcepub fn bulkhead_full() -> Error
pub fn bulkhead_full() -> Error
The scope already has as many calls in flight as its bulkhead allows.
Sourcepub fn cancelled() -> Error
pub fn cancelled() -> Error
The caller dropped the future before it finished — a tokio::time::timeout that
expired, a select! that took another branch. Nobody is waiting for this error: it
is what the operation hooks are told the call ended as, so the bookkeeping every
layer keeps per operation is closed out rather than left open.
It is a ErrorCode::Network because that is what a call that never got an answer
is. It is not retryable: there is nobody left to answer. It does not count against
the circuit breaker — a deadline the caller chose says nothing about Fizzy.
Sourcepub fn api(status: u16, message: impl Into<String>) -> Error
pub fn api(status: u16, message: impl Into<String>) -> Error
The server answered with a failure.
Sourcepub fn response_too_large(limit: usize, method: &Method, path: &str) -> Error
pub fn response_too_large(limit: usize, method: &Method, path: &str) -> Error
A body the client refused to read, because reading it whole is what the caller would have gone on to do. It carries no HTTP status of its own: the answer never arrived in full, so there is nothing to report about it but the refusal.
Sourcepub fn validation(messages: &[String]) -> Error
pub fn validation(messages: &[String]) -> Error
The messages the server itself produced, joined. With none of them the error still says something: “validation error”.
Sourcepub fn ambiguous(resource: &str, matches: &[String]) -> Error
pub fn ambiguous(resource: &str, matches: &[String]) -> Error
A name that matched more than one record. Up to five matches are named in the hint; beyond that the only useful advice is to narrow the search.
Sourcepub fn from_std(source: impl Error + Send + Sync + 'static) -> Error
pub fn from_std(source: impl Error + Send + Sync + 'static) -> Error
Wraps an error from outside the SDK as an API error that reads the way the original did, for the callers that have to answer with this type and nothing better fits.
Sourcepub fn from_response(
status: StatusCode,
method: &Method,
headers: &HeaderMap,
body: &[u8],
) -> Error
pub fn from_response( status: StatusCode, method: &Method, headers: &HeaderMap, body: &[u8], ) -> Error
Maps a non-2xx response onto the SDK’s error vocabulary. The hint carries whatever
message the server put in the body, when it sent one, and the body itself is kept on
the error for a caller that needs more of it than a hint — see Error::body.
Sourcepub fn with_status(self, status: u16) -> Error
pub fn with_status(self, status: u16) -> Error
Records the HTTP status.
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Error
pub fn with_request_id(self, request_id: impl Into<String>) -> Error
Records the server’s request id.
Sourcepub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Error
pub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Error
Records what caused this.
Sourcepub fn exit_code(&self) -> i32
pub fn exit_code(&self) -> i32
The process exit status a command should end with for this error.
Sourcepub fn http_status(&self) -> Option<u16>
pub fn http_status(&self) -> Option<u16>
The HTTP status, when the server answered.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether resending would be worth trying.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
The server’s X-Request-Id, when it sent one.
Sourcepub fn refusal(&self) -> Option<Refusal>
pub fn refusal(&self) -> Option<Refusal>
Which of the SDK’s own layers turned the call away, when one did.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
The caller gave up on the call before it finished. See Error::cancelled.
Sourcepub fn is_response_too_large(&self) -> bool
pub fn is_response_too_large(&self) -> bool
The answer was longer than the client will hold in memory, whether that refusal is the error itself or sits behind the status the answer carried.
Sourcepub fn body(&self) -> Option<&[u8]>
pub fn body(&self) -> Option<&[u8]>
What Fizzy answered the failure with, up to MAX_ERROR_BODY_BYTES. A 422 describes
the fields it objected to in the body, and this is where that account is kept. It is
None when the answer carried no body, when the SDK raised the error itself, and
when the body was too long to read.
Sourcepub fn body_json<T: DeserializeOwned>(&self) -> Option<T>
pub fn body_json<T: DeserializeOwned>(&self) -> Option<T>
The failure body read as T, or None when there is no body or it does not read as
one.
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()