Skip to main content

SlabError

Enum SlabError 

Source
#[non_exhaustive]
pub enum SlabError { Validation { field: String, message: String, }, ValidationErrors(BTreeMap<String, Vec<String>>), BadRequest(String), Unauthorized(String), Forbidden(String), NotFound(String), Conflict(String), TooManyRequests { retry_after_secs: u64, message: String, }, Database(Error), Internal(String), }
Expand description

Unified HTTP error type returned by every transaction script and background job.

Implements IntoResponse with JSON error bodies and explicit HTTP status codes.

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

Validation

Input validation failure targeting a specific field (HTTP 422, error: "validation_error").

Fields

§field: String

Name of the field that failed validation.

§message: String

Human-readable description of the validation failure.

§

ValidationErrors(BTreeMap<String, Vec<String>>)

Multi-field input validation failure (HTTP 422, error: "validation_error").

§

BadRequest(String)

Malformed or invalid client request (HTTP 400, error: "bad_request").

§

Unauthorized(String)

Missing or invalid authentication credentials (HTTP 401, error: "unauthorized").

§

Forbidden(String)

Authenticated caller lacks permission for the requested action (HTTP 403, error: "forbidden").

§

NotFound(String)

Requested resource does not exist (HTTP 404, error: "not_found").

§

Conflict(String)

Resource state conflict, such as a duplicate unique key (HTTP 409, error: "conflict").

§

TooManyRequests

Rate limit exceeded (HTTP 429, error: "too_many_requests").

Sets the Retry-After response header to retry_after_secs.

Fields

§retry_after_secs: u64

Seconds the client should wait before retrying.

§message: String

Human-readable rate-limit explanation.

§

Database(Error)

Underlying sqlx database error.

Maps sqlx::Error::RowNotFound to HTTP 404 ("record not found"). Maps all other database errors to HTTP 500 and logs the raw error with tracing::error!.

§

Internal(String)

Unexpected server-side failure (HTTP 500, error: "internal_error").

Logs the message with tracing::error! and returns "internal server error" to clients.

Implementations§

Source§

impl SlabError

Source

pub fn validation(field: impl Into<String>, message: impl Into<String>) -> Self

Creates a SlabError::Validation error (HTTP 422) for field with message.

Source

pub fn bad_request(msg: impl Into<String>) -> Self

Creates a SlabError::BadRequest error (HTTP 400).

Source

pub fn unauthorized(msg: impl Into<String>) -> Self

Creates a SlabError::Unauthorized error (HTTP 401).

Source

pub fn forbidden(msg: impl Into<String>) -> Self

Creates a SlabError::Forbidden error (HTTP 403).

Source

pub fn not_found(msg: impl Into<String>) -> Self

Creates a SlabError::NotFound error (HTTP 404).

Source

pub fn conflict(msg: impl Into<String>) -> Self

Creates a SlabError::Conflict error (HTTP 409).

Source

pub fn too_many_requests(retry_after_secs: u64, msg: impl Into<String>) -> Self

Creates a SlabError::TooManyRequests error (HTTP 429) with a Retry-After value in seconds.

Source

pub fn internal(msg: impl Into<String>) -> Self

Creates a SlabError::Internal error (HTTP 500).

Source

pub fn status_code(&self) -> StatusCode

Returns the HTTP StatusCode mapped to this error variant.

Trait Implementations§

Source§

impl Debug for SlabError

Source§

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

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

impl Display for SlabError

Source§

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

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

impl Error for SlabError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for SlabError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for SlabError

Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

§

impl !RefUnwindSafe for SlabError

§

impl !UnwindSafe for SlabError

§

impl Forget for SlabError

§

impl Freeze for SlabError
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const LeafNode<String, Vec<String>> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, Vec<String>)>>: Freeze, *const dyn Error + Sync + Send is !null: Freeze, PhantomData<dyn Error + Sync + Send>: Freeze, *const dyn DatabaseError is !null: Freeze, PhantomData<dyn DatabaseError>: Freeze, *const () is !null: Freeze, PhantomData<ErrorData<CustomOwner>>: Freeze, *const MigrateError is !null: Freeze, PhantomData<MigrateError>: Freeze,

§

impl Move for SlabError

§

impl Send for SlabError
where RawVecInner: Send, NodeRef<Owned, String, Vec<String>, LeafOrInternal>: Send, BoxRaw<(String, Vec<String>)>: Send, BoxRaw<dyn Error + Sync + Send>: Send, BoxRaw<dyn DatabaseError>: Send, Repr: Send, BoxRaw<MigrateError>: Send,

§

impl Sync for SlabError
where RawVecInner: Sync, NodeRef<Owned, String, Vec<String>, LeafOrInternal>: Sync, BoxRaw<(String, Vec<String>)>: Sync, BoxRaw<dyn Error + Sync + Send>: Sync, BoxRaw<dyn DatabaseError>: Sync, Repr: Sync, BoxRaw<MigrateError>: Sync,

§

impl Unpin for SlabError
where *const u8 is !null: Unpin, *const LeafNode<String, Vec<String>> is !null: Unpin, Box<(String, Vec<String>)>: Unpin, Box<dyn Error + Sync + Send>: Unpin, Box<dyn DatabaseError>: Unpin, *const () is !null: Unpin, &'static SimpleMessage: Unpin, *const Custom is !null: Unpin, Box<MigrateError>: Unpin,

§

impl UnsafeUnpin for SlabError

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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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