pub struct Error { /* private fields */ }Expand description
A framework error: a kind, a human message, an optional
structured details payload, and an optional underlying cause.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(kind: ErrorKind, message: impl Into<String>) -> Self
pub fn new(kind: ErrorKind, message: impl Into<String>) -> Self
Build an error of an explicit kind.
Sourcepub fn bad_request(message: impl Into<String>) -> Self
pub fn bad_request(message: impl Into<String>) -> Self
400 — a malformed request.
Sourcepub fn unauthenticated(message: impl Into<String>) -> Self
pub fn unauthenticated(message: impl Into<String>) -> Self
401 — missing or invalid credentials.
403 — authenticated but not permitted.
Sourcepub fn request_timeout(message: impl Into<String>) -> Self
pub fn request_timeout(message: impl Into<String>) -> Self
408 — the request took longer than this service is prepared to wait.
What a Timeout middleware
returns. 408 rather than 504: the timeout is this service’s own
decision about its own handler, not a report about something upstream.
Sourcepub fn too_many_requests(message: impl Into<String>) -> Self
pub fn too_many_requests(message: impl Into<String>) -> Self
429 — throttled.
The caller should also send a retry-after; nothing here can know what
to put in it.
503 — a dependency is down, or the application is in maintenance.
The honest answer when a health check cannot reach the database. A 500 says “this service is broken”; a 503 says “try again”, which is what a load balancer and a retrying client both need to hear.
Sourcepub fn validation(details: Value) -> Self
pub fn validation(details: Value) -> Self
422 with a structured field-error payload — what a failed
FormRequest produces.
Sourcepub fn with_details(self, details: Value) -> Self
pub fn with_details(self, details: Value) -> Self
Attach a structured payload rendered alongside the message.
Sourcepub fn with_source(self, source: impl Into<Error>) -> Self
pub fn with_source(self, source: impl Into<Error>) -> Self
Attach the underlying cause.
Sourcepub fn with_kind(self, kind: ErrorKind) -> Self
pub fn with_kind(self, kind: ErrorKind) -> Self
Re-label the kind (and therefore the status) without losing the rest.
Sourcepub fn source_error(&self) -> Option<&Error>
pub fn source_error(&self) -> Option<&Error>
The underlying cause, if one was attached.
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()