v0.0.5
RustBox CI / rustbox (push) Canceled after 0s

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-30 12:06:44 +01:00
1 parent 96a32ea8fb
commit a643e7e3ab
106 files changed
+2223 -4669

No files matched your search

+6 -14
View File
@@ -2,13 +2,11 @@ use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use serde::Serialize;
/// Structured JSON error envelope returned to clients.
#[derive(Debug, Serialize)]
struct ErrorEnvelope {
error: ErrorBody,
}
/// Body of the error envelope.
#[derive(Debug, Serialize)]
struct ErrorBody {
code: String,
@@ -16,29 +14,25 @@ struct ErrorBody {
status: u16,
}
/// Application-level error type that converts into an Axum response
/// with a structured JSON error envelope.
#[derive(Debug)]
#[allow(dead_code)]
pub enum AppError {
/// Internal server error (500).
InternalError(String),
/// Resource not found (404).
NotFound(String),
/// Unauthorized access (401).
Unauthorized(String),
/// Bad request (400).
BadRequest(String),
/// Authenticated but forbidden by policy (403).
Forbidden(String),
/// Service unavailable (503).
ServiceUnavailable(String),
/// Request payload is larger than the configured mail limit (413).
PayloadTooLarge(String),
}
impl AppError {
/// Returns the HTTP status code for this error variant.
fn status_code(&self) -> StatusCode {
match self {
AppError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
@@ -51,7 +45,6 @@ impl AppError {
}
}
/// Returns the error code string for this error variant.
fn error_code(&self) -> &'static str {
match self {
AppError::InternalError(_) => "INTERNAL_ERROR",
@@ -64,7 +57,6 @@ impl AppError {
}
}
/// Returns the human-readable message for this error variant.
fn message(&self) -> &str {
match self {
AppError::InternalError(msg)