Skip to main content

AppError

Enum AppError 

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

§

Unauthorized(String)

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

§message: String

Summary validation failure message.

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

§

ServiceUnavailable(String)

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 source and context are emitted to the structured tracing log at ERROR level, 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

§source: Box<dyn Error + Send + Sync>

The underlying source error causing the failure.

§context: String

Descriptive contextual summary of where/why the error occurred.

§

Custom

Custom error variant for domain-specific HTTP responses.

Fields

§status: StatusCode

HTTP status code for the response.

§code: String

Machine-readable error code string (used in RFC 7807 title).

§message: String

Client-facing detail message.

Implementations§

Source§

impl AppError

Source

pub fn internal_from<E>(err: E, ctx: impl Into<String>) -> AppError
where E: Error + Send + Sync + 'static,

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"))
}
Source

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);
Source

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);
Source

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 Debug for AppError

Source§

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

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

impl Display for AppError

Source§

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

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

impl Error for AppError

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

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<AbacError> for AppError

Source§

fn from(err: AbacError) -> AppError

Converts an AbacError into an RFC 7807 AppError response.

Source§

impl From<AuthError> for AppError

Source§

fn from(err: AuthError) -> AppError

Converts an AuthError into an RFC 7807 AppError response (401 Unauthorized, 403 Forbidden, 422 Unprocessable, or 500 Internal).

Source§

impl From<CedarError> for AppError

Source§

fn from(e: CedarError) -> AppError

Converts to this type from the input type.
Source§

impl From<DbError> for AppError

Source§

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

Source§

fn from(err: ExtractorError) -> AppError

Converts to this type from the input type.
Source§

impl From<IdempotencyError> for AppError

Source§

fn from(err: IdempotencyError) -> AppError

Converts to this type from the input type.
Source§

impl From<NotifyError> for AppError

Source§

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

Source§

fn from(err: PaginationError) -> AppError

Converts to this type from the input type.
Source§

impl From<RealtimeError> for AppError

Source§

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

Source§

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

Source§

fn from(err: WebhookError) -> AppError

Converts to this type from the input type.
Source§

impl From<WorkerError> for AppError

Source§

fn from(err: WorkerError) -> AppError

Converts to this type from the input type.
Source§

impl IntoResponse for AppError

Source§

fn into_response(self) -> Response<Body>

Create a response.

Auto Trait Implementations§

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<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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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> ToCompactString for T
where T: Display,

Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

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