#[non_exhaustive]pub enum Error {
BadRequest(String),
Unauthorized,
Forbidden,
NotFound,
PageExpired,
TooManyRequests,
ServiceUnavailable,
Validation(ValidationError),
Status(StatusCode, String),
Internal(Error),
}Expand description
The error type handlers return. Any anyhow-compatible error converts into
Error::Internal with ?.
For a status without its own variant (402, 409, 410, …) use
Error::Status, or abort / abort_if:
fn download(order: &Order) -> Result<&'static str> {
renox::abort_if(!order.paid, StatusCode::PAYMENT_REQUIRED, "Pay for the order first.")?;
Ok("the file")
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
BadRequest(String)
400, with a message that is safe to show visitors.
401: the request needs a logged-in user.
Forbidden
403: the user may not do this.
NotFound
PageExpired
The CSRF token was missing or wrong, usually because the session expired.
TooManyRequests
A rate limit was hit; see Routes::throttle.
The app is in maintenance mode.
Validation(ValidationError)
Invalid input; see ValidationError.
Status(StatusCode, String)
Any status, with a message that is safe to show visitors (on the
error page, or as message in JSON).
Internal(Error)
500 (409 for a unique-constraint violation); details are shown only in debug.
Implementations§
Source§impl Error
impl Error
Sourcepub fn permanent(err: impl Into<Error>) -> Self
pub fn permanent(err: impl Into<Error>) -> Self
An error that retrying can’t fix, e.g. an invalid email address. A job
that returns one goes to failed_jobs at once instead of being retried.
Sourcepub fn permanent_message(message: impl Display) -> Self
pub fn permanent_message(message: impl Display) -> Self
Error::permanent with just a message:
Err(Error::permanent_message("the card was declined")).
Sourcepub fn is_permanent(&self) -> bool
pub fn is_permanent(&self) -> bool
Whether the error was made with Error::permanent.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether the error is a database conflict that retrying may clear (see
DbError::is_retryable).
Sourcepub fn is_unique_violation(&self) -> bool
pub fn is_unique_violation(&self) -> bool
Whether the error is a database unique-constraint violation, e.g. a
second sign-up with the same email racing past the unique rule.
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
The HTTP status this error responds with.
Trait Implementations§
Source§impl From<ValidationError> for Error
impl From<ValidationError> for Error
Source§fn from(err: ValidationError) -> Self
fn from(err: ValidationError) -> Self
Source§impl IntoResponse for Error
impl IntoResponse for Error
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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