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>) -> Error
pub fn new(kind: ErrorKind, message: impl Into<String>) -> Error
Build an error of an explicit kind.
Sourcepub fn bad_request(message: impl Into<String>) -> Error
pub fn bad_request(message: impl Into<String>) -> Error
400 — a malformed request.
Sourcepub fn unauthenticated(message: impl Into<String>) -> Error
pub fn unauthenticated(message: impl Into<String>) -> Error
401 — missing or invalid credentials.
403 — authenticated but not permitted.
Sourcepub fn request_timeout(message: impl Into<String>) -> Error
pub fn request_timeout(message: impl Into<String>) -> Error
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>) -> Error
pub fn too_many_requests(message: impl Into<String>) -> Error
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) -> Error
pub fn validation(details: Value) -> Error
422 with a structured field-error payload — what a failed
FormRequest
produces.
Sourcepub fn with_details(self, details: Value) -> Error
pub fn with_details(self, details: Value) -> Error
Attach a structured payload rendered alongside the message.
Sourcepub fn with_source(self, source: impl Into<Error>) -> Error
pub fn with_source(self, source: impl Into<Error>) -> Error
Attach the underlying cause.
Sourcepub fn with_kind(self, kind: ErrorKind) -> Error
pub fn with_kind(self, kind: ErrorKind) -> Error
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()
Source§impl From<ValidationErrors> for Error
impl From<ValidationErrors> for Error
Source§fn from(errors: ValidationErrors) -> Error
fn from(errors: ValidationErrors) -> Error
A 422 carrying the failures as structured details, which the HTTP
layer renders without knowing anything about validation.
Source§impl IntoResponse for Error
Renders a framework error as JSON.
impl IntoResponse for Error
Renders a framework error as JSON.
The default, and what an API client should get. The HTTP kernel wraps it
with content negotiation — an HTML error page for a browser — using the
RenderedError this attaches.
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
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
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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