#[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
Validation
Input validation failure targeting a specific field (HTTP 422, error: "validation_error").
Fields
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").
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>,
) -> SlabError
pub fn validation( field: impl Into<String>, message: impl Into<String>, ) -> SlabError
Creates a SlabError::Validation error (HTTP 422) for field with message.
Sourcepub fn bad_request(msg: impl Into<String>) -> SlabError
pub fn bad_request(msg: impl Into<String>) -> SlabError
Creates a SlabError::BadRequest error (HTTP 400).
Creates a SlabError::Unauthorized error (HTTP 401).
Sourcepub fn forbidden(msg: impl Into<String>) -> SlabError
pub fn forbidden(msg: impl Into<String>) -> SlabError
Creates a SlabError::Forbidden error (HTTP 403).
Sourcepub fn not_found(msg: impl Into<String>) -> SlabError
pub fn not_found(msg: impl Into<String>) -> SlabError
Creates a SlabError::NotFound error (HTTP 404).
Sourcepub fn conflict(msg: impl Into<String>) -> SlabError
pub fn conflict(msg: impl Into<String>) -> SlabError
Creates a SlabError::Conflict error (HTTP 409).
Sourcepub fn too_many_requests(
retry_after_secs: u64,
msg: impl Into<String>,
) -> SlabError
pub fn too_many_requests( retry_after_secs: u64, msg: impl Into<String>, ) -> SlabError
Creates a SlabError::TooManyRequests error (HTTP 429) with a Retry-After value in seconds.
Sourcepub fn internal(msg: impl Into<String>) -> SlabError
pub fn internal(msg: impl Into<String>) -> SlabError
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<Body>
fn into_response(self) -> Response<Body>
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 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
impl Sync for SlabError
impl Unpin for SlabErrorwhere
*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 SlabErrorwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const LeafNode<String, Vec<String>> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, Vec<String>)>>: 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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn compression(self) -> Compression<Self>where
Self: Sized,
fn compression(self) -> Compression<Self>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
Source§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
x-request-id as the header name. Read moreSource§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
Source§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
x-request-id as the header name. Read moreSource§fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
413 Payload Too Large responses. Read more