Skip to main content

Error

Enum Error 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

BadRequest(String)

400, with a message that is safe to show visitors.

§

Unauthorized

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.

§

ServiceUnavailable

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

Source

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.

Source

pub fn permanent_message(message: impl Display) -> Self

Error::permanent with just a message: Err(Error::permanent_message("the card was declined")).

Source

pub fn is_permanent(&self) -> bool

Whether the error was made with Error::permanent.

Source

pub fn is_retryable(&self) -> bool

Whether the error is a database conflict that retrying may clear (see DbError::is_retryable).

Source

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.

Source

pub fn status(&self) -> StatusCode

The HTTP status this error responds with.

Trait Implementations§

Source§

impl Debug for Error

Readable when main returns an error: the message and its causes.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Into<Error>> From<E> for Error

Source§

fn from(err: E) -> Self

Converts to this type from the input type.
Source§

impl From<Errors> for Error

Source§

fn from(errors: Errors) -> Self

Converts to this type from the input type.
Source§

impl From<ValidationError> for Error

Source§

fn from(err: ValidationError) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for Error

Source§

fn into_response(self) -> Response

Create a 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more