pub enum AppError {
BadRequest(String),
Unauthorized(String),
Forbidden(String),
NotFound(String),
Conflict(String),
UnprocessableEntity(String),
ValidationError {
message: String,
details: Vec<ErrorDetails>,
},
PaymentRequired(String),
TooManyRequests(String),
ServiceUnavailable(String),
Internal {
source: Box<dyn Error + Send + Sync>,
context: String,
},
Custom {
status: StatusCode,
code: String,
message: String,
},
}Expand description
The canonical error type for all Scyph-based HTTP backends.
AppError maps domain and runtime errors into standardized HTTP status codes
and RFC 7807 Problem Details JSON responses when returned from Axum handlers.
Internal errors (AppError::Internal) log the underlying source error using tracing::error!
while returning an opaque message to clients, preventing internal leaks.
Variants§
BadRequest(String)
400 Bad Request — Malformed or invalid input that the client can fix.
401 Unauthorized — Missing, invalid, or expired authentication credentials.
Forbidden(String)
403 Forbidden — Authenticated entity lacks permission to access the resource.
NotFound(String)
404 Not Found — Requested resource could not be found.
Conflict(String)
409 Conflict — Resource state conflict (e.g., duplicate email address on registration).
UnprocessableEntity(String)
422 Unprocessable Entity — Request syntax is correct but validation failed.
ValidationError
422 Unprocessable Entity — Structured request validation failure with field-level details.
Fields
details: Vec<ErrorDetails>List of field-level validation errors.
PaymentRequired(String)
402 Payment Required — Access requires payment or active subscription.
TooManyRequests(String)
429 Too Many Requests — Client has exceeded rate limit thresholds.
503 Service Unavailable — Server is temporarily overloaded or under maintenance.
Internal
500 Internal Server Error — Unexpected internal failure.
The full error context is logged via tracing::error!, but the client receives an
opaque generic detail message "An unexpected error occurred." to preserve security.
§Security Masking
This variant intentionally hides the underlying source error and context from HTTP
clients. Exposing database errors, stack traces, or internal service messages in API
responses is a common information-disclosure vulnerability (CWE-209). Instead:
- The
sourceandcontextare emitted to the structured tracing log atERRORlevel, visible in your log aggregator (e.g., CloudWatch, Datadog). - The HTTP response body always contains the fixed string
"An unexpected error occurred.".
This makes internal errors safe to return from any handler without risk of leaking secrets, database schema details, or service internals to end users.
Fields
Custom
Custom error variant for domain-specific HTTP responses.
Implementations§
Source§impl AppError
impl AppError
Sourcepub fn internal_from<E>(err: E, ctx: impl Into<String>) -> AppError
pub fn internal_from<E>(err: E, ctx: impl Into<String>) -> AppError
Wraps any standard error (std::error::Error) into an internal server error variant (AppError::Internal).
The underlying error will be logged internally via tracing, while the response detail sent
to the client is masked for security.
§Arguments
err- The underlying source error.ctx- A human-readable context description explaining where the error occurred.
§Security Note
The err and ctx values are logged at ERROR level via tracing but are never
included in the HTTP response body. Clients always receive the opaque message
"An unexpected error occurred.".
§Examples
Wrapping a standard parse error:
use scyph_core::AppError;
let parse_result: Result<i32, _> = "invalid".parse();
let app_err = parse_result.map_err(|e| AppError::internal_from(e, "Failed to parse integer"));
assert_eq!(app_err.unwrap_err().status(), axum::http::StatusCode::INTERNAL_SERVER_ERROR);Wrapping a sqlx database error (requires sqlx in scope):
use scyph_core::AppError;
async fn get_user(pool: &sqlx::PgPool, id: uuid::Uuid) -> Result<String, AppError> {
sqlx::query_scalar::<_, String>("SELECT name FROM users WHERE id = $1")
.bind(id)
.fetch_one(pool)
.await
.map_err(|e| AppError::internal_from(e, "get_user: failed to query users table"))
}Sourcepub fn internal(ctx: impl Into<String>) -> AppError
pub fn internal(ctx: impl Into<String>) -> AppError
Creates an internal server error (AppError::Internal) from a plain string message context
without a separate underlying source error.
§Arguments
ctx- A message explaining the context of the internal failure.
§Examples
use scyph_core::AppError;
let err = AppError::internal("Database connection pool exhausted");
assert_eq!(err.status(), axum::http::StatusCode::INTERNAL_SERVER_ERROR);Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the HTTP status code associated with this error variant.
§Examples
use scyph_core::AppError;
use axum::http::StatusCode;
let err = AppError::NotFound("Item missing".into());
assert_eq!(err.status(), StatusCode::NOT_FOUND);Sourcepub fn code(&self) -> &str
pub fn code(&self) -> &str
Returns a machine-readable string error code identifier (e.g., "NOT_FOUND", "UNAUTHORIZED").
This string populates the title field in the RFC 7807 JSON error response.
§Examples
use scyph_core::AppError;
let err = AppError::Unauthorized("Invalid token".into());
assert_eq!(err.code(), "UNAUTHORIZED");Trait Implementations§
Source§impl Error for AppError
impl Error for AppError
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 From<CedarError> for AppError
impl From<CedarError> for AppError
Source§fn from(e: CedarError) -> AppError
fn from(e: CedarError) -> AppError
Source§impl From<DbError> for AppError
impl From<DbError> for AppError
Source§fn from(err: DbError) -> AppError
fn from(err: DbError) -> AppError
Converts any DbError into an AppError::internal error.
This blanket conversion allows DbError to be propagated through Axum handlers
and service functions that return Result<_, AppError> using the ? operator.
The error message from the DbError variant is preserved in the internal error body.
Source§impl From<ExtractorError> for AppError
impl From<ExtractorError> for AppError
Source§fn from(err: ExtractorError) -> AppError
fn from(err: ExtractorError) -> AppError
Source§impl From<IdempotencyError> for AppError
impl From<IdempotencyError> for AppError
Source§fn from(err: IdempotencyError) -> AppError
fn from(err: IdempotencyError) -> AppError
Source§impl From<NotifyError> for AppError
impl From<NotifyError> for AppError
Source§fn from(err: NotifyError) -> AppError
fn from(err: NotifyError) -> AppError
Converts a NotifyError into an HTTP 500 RFC 7807 AppError for Axum API responses.
Source§impl From<PaginationError> for AppError
impl From<PaginationError> for AppError
Source§fn from(err: PaginationError) -> AppError
fn from(err: PaginationError) -> AppError
Source§impl From<RealtimeError> for AppError
impl From<RealtimeError> for AppError
Source§fn from(err: RealtimeError) -> AppError
fn from(err: RealtimeError) -> AppError
Converts a RealtimeError into an RFC 7807 AppError response.
All variants map to 500 Internal Server Error since realtime errors are
infrastructure-level failures not attributable to client input.
Source§impl From<StorageError> for AppError
impl From<StorageError> for AppError
Source§fn from(err: StorageError) -> AppError
fn from(err: StorageError) -> AppError
Maps a StorageError to the appropriate HTTP status code and RFC 7807 AppError response.
Source§impl From<WebhookError> for AppError
impl From<WebhookError> for AppError
Source§fn from(err: WebhookError) -> AppError
fn from(err: WebhookError) -> AppError
Source§impl From<WorkerError> for AppError
impl From<WorkerError> for AppError
Source§fn from(err: WorkerError) -> AppError
fn from(err: WorkerError) -> AppError
Source§impl IntoResponse for AppError
impl IntoResponse for AppError
Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
Auto Trait Implementations§
impl !RefUnwindSafe for AppError
impl !UnwindSafe for AppError
impl Freeze for AppError
impl Send for AppError
impl Sync for AppError
impl Unpin for AppError
impl UnsafeUnpin for AppError
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§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> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more