pub struct Error { /* private fields */ }Expand description
An error carrying the HTTP status it should be rendered with.
Any std::error::Error converts into a 500 Internal Server Error via ?,
so handlers can bubble failures up without ceremony. Use the constructors
(Error::not_found(), Error::bad_request(..), …) for client errors.
Like anyhow::Error, this type deliberately does not implement
std::error::Error itself; that is what makes the blanket From possible.
Implementations§
Source§impl Error
impl Error
pub fn new(status: StatusCode, message: impl Into<String>) -> Self
Sourcepub fn with_source(
status: StatusCode,
message: impl Into<String>,
source: impl Error + Send + Sync + 'static,
) -> Self
pub fn with_source( status: StatusCode, message: impl Into<String>, source: impl Error + Send + Sync + 'static, ) -> Self
An error with source as its cause, kept for
downcast_ref and the logs.
Sourcepub fn downcast_ref<E: Error + 'static>(&self) -> Option<&E>
pub fn downcast_ref<E: Error + 'static>(&self) -> Option<&E>
The cause, if it’s an E: err.downcast_ref::<ClientError>()
says why a call to another service failed.
pub fn not_found() -> Self
pub fn bad_request(message: impl Into<String>) -> Self
pub fn unprocessable(message: impl Into<String>) -> Self
pub fn internal(message: impl Into<String>) -> Self
pub fn status(&self) -> StatusCode
pub fn message(&self) -> &str
Trait Implementations§
Source§impl From<MultiError> for Error
So multi.commit().await? works in an action: an invalid step is a
422 carrying its errors, anything else the step’s own error.
impl From<MultiError> for Error
So multi.commit().await? works in an action: an invalid step is a
422 carrying its errors, anything else the step’s own error.
Source§fn from(err: MultiError) -> Self
fn from(err: MultiError) -> Self
Converts to this type from the input type.
Source§impl IntoResponse for Error
impl IntoResponse for Error
fn into_response(self) -> Response
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
Converts
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> ⓘ
Converts
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