#[non_exhaustive]pub enum SlabError {
Validation {
field: String,
message: 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
Validation
Input validation failure targeting a specific field (HTTP 422, error: "validation_error").
Fields
BadRequest(String)
Malformed or invalid client request (HTTP 400, error: "bad_request").
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
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
impl SlabError
Sourcepub fn validation(field: impl Into<String>, message: impl Into<String>) -> Self
pub fn validation(field: impl Into<String>, message: impl Into<String>) -> Self
Creates a SlabError::Validation error (HTTP 422) for field with message.
Sourcepub fn bad_request(msg: impl Into<String>) -> Self
pub fn bad_request(msg: impl Into<String>) -> Self
Creates a SlabError::BadRequest error (HTTP 400).
Creates a SlabError::Unauthorized error (HTTP 401).
Sourcepub fn forbidden(msg: impl Into<String>) -> Self
pub fn forbidden(msg: impl Into<String>) -> Self
Creates a SlabError::Forbidden error (HTTP 403).
Sourcepub fn not_found(msg: impl Into<String>) -> Self
pub fn not_found(msg: impl Into<String>) -> Self
Creates a SlabError::NotFound error (HTTP 404).
Sourcepub fn conflict(msg: impl Into<String>) -> Self
pub fn conflict(msg: impl Into<String>) -> Self
Creates a SlabError::Conflict error (HTTP 409).
Sourcepub fn too_many_requests(retry_after_secs: u64, msg: impl Into<String>) -> Self
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.
Sourcepub fn internal(msg: impl Into<String>) -> Self
pub fn internal(msg: impl Into<String>) -> Self
Creates a SlabError::Internal error (HTTP 500).
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Returns the HTTP StatusCode mapped to this error variant.
Trait Implementations§
Source§impl Error for SlabError
impl Error for SlabError
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 IntoResponse for SlabError
impl IntoResponse for SlabError
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl !RefUnwindSafe for SlabError
impl !UnwindSafe for SlabError
impl Forget for SlabError
impl Freeze for SlabErrorwhere
*const u8 is !null: Freeze,
PhantomData<u8>: 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 SlabErrorwhere
RawVecInner: Send,
BoxRaw<dyn Error + Sync + Send>: Send,
BoxRaw<dyn DatabaseError>: Send,
Repr: Send,
BoxRaw<MigrateError>: Send,
impl Sync for SlabErrorwhere
RawVecInner: Sync,
BoxRaw<dyn Error + Sync + Send>: Sync,
BoxRaw<dyn DatabaseError>: Sync,
Repr: Sync,
BoxRaw<MigrateError>: Sync,
impl Unpin for SlabError
impl UnsafeUnpin for SlabErrorwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const dyn Error + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Error + Sync + Send>: UnsafeUnpin,
*const dyn DatabaseError is !null: UnsafeUnpin,
PhantomData<dyn DatabaseError>: UnsafeUnpin,
*const () is !null: UnsafeUnpin,
PhantomData<ErrorData<CustomOwner>>: UnsafeUnpin,
*const MigrateError is !null: UnsafeUnpin,
PhantomData<MigrateError>: UnsafeUnpin,
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