feat: v0.3.0 — standardize codebase, centralize infra, merge QR into CMS
- Enforce axum best practices across all 13 workspace crates (max 200 LOC/file, no comments, no unwrap, clean architecture) - Fix domain→infrastructure dependency inversions in imphnen-iam and imphnen-dimentorin - Extract imphnen-storage (MinIO) and imphnen-email (Lettre) as standalone crates - Centralize all config in ENV struct: CDN_URL, CORS_ALLOWED_ORIGINS - Centralize SMTP through imphnen-email; remove dead HackathonConfig - Centralize database: QR crate now shares main DB pool (single DATABASE_URL) - Rename QR users table to qr_users to avoid collision with main users table - Merge imphnen-qr into imphnen-cms/src/qr (13 crates, down from 14) - Restructure imphnen-hackathon flat modules into clean architecture - Remove all stale env vars from .env.example (SurrealDB, QR_JWT, Hackathon infra) - Fix Dockerfile to include all current workspace crates - Bump all crate versions 0.2.0 → 0.3.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2ae43b3bcc
commit
331a4a4e88
+124
-114
@@ -1,114 +1,124 @@
|
||||
use axum::{
|
||||
Json,
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum AppError {
|
||||
ValidationError(String),
|
||||
AuthenticationError(String),
|
||||
AuthorizationError(String),
|
||||
NotFoundError(String),
|
||||
ConflictError(String),
|
||||
InternalServerError(String),
|
||||
BadRequestError(String),
|
||||
ForbiddenError(String),
|
||||
PaymentRequiredError(String),
|
||||
MethodNotAllowedError(String),
|
||||
NotAcceptableError(String),
|
||||
RequestTimeoutError(String),
|
||||
TooManyRequestsError(String),
|
||||
GatewayTimeoutError(String),
|
||||
ServiceUnavailableError(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AppError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
AppError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
|
||||
AppError::AuthenticationError(msg) => write!(f, "Authentication failed: {}", msg),
|
||||
AppError::AuthorizationError(msg) => write!(f, "Authorization failed: {}", msg),
|
||||
AppError::NotFoundError(msg) => write!(f, "Resource not found: {}", msg),
|
||||
AppError::ConflictError(msg) => write!(f, "Conflict error: {}", msg),
|
||||
AppError::InternalServerError(msg) => write!(f, "Internal server error: {}", msg),
|
||||
AppError::BadRequestError(msg) => write!(f, "Bad request: {}", msg),
|
||||
AppError::ForbiddenError(msg) => write!(f, "Forbidden: {}", msg),
|
||||
AppError::PaymentRequiredError(msg) => write!(f, "Payment required: {}", msg),
|
||||
AppError::MethodNotAllowedError(msg) => write!(f, "Method not allowed: {}", msg),
|
||||
AppError::NotAcceptableError(msg) => write!(f, "Not acceptable: {}", msg),
|
||||
AppError::RequestTimeoutError(msg) => write!(f, "Request timeout: {}", msg),
|
||||
AppError::TooManyRequestsError(msg) => write!(f, "Too many requests: {}", msg),
|
||||
AppError::GatewayTimeoutError(msg) => write!(f, "Gateway timeout: {}", msg),
|
||||
AppError::ServiceUnavailableError(msg) => write!(f, "Service unavailable: {}", msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppError {
|
||||
pub fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
AppError::ValidationError(_) => StatusCode::BAD_REQUEST,
|
||||
AppError::AuthenticationError(_) => StatusCode::UNAUTHORIZED,
|
||||
AppError::AuthorizationError(_) => StatusCode::FORBIDDEN,
|
||||
AppError::NotFoundError(_) => StatusCode::NOT_FOUND,
|
||||
AppError::ConflictError(_) => StatusCode::CONFLICT,
|
||||
AppError::InternalServerError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
AppError::BadRequestError(_) => StatusCode::BAD_REQUEST,
|
||||
AppError::ForbiddenError(_) => StatusCode::FORBIDDEN,
|
||||
AppError::PaymentRequiredError(_) => StatusCode::PAYMENT_REQUIRED,
|
||||
AppError::MethodNotAllowedError(_) => StatusCode::METHOD_NOT_ALLOWED,
|
||||
AppError::NotAcceptableError(_) => StatusCode::NOT_ACCEPTABLE,
|
||||
AppError::RequestTimeoutError(_) => StatusCode::REQUEST_TIMEOUT,
|
||||
AppError::TooManyRequestsError(_) => StatusCode::TOO_MANY_REQUESTS,
|
||||
AppError::GatewayTimeoutError(_) => StatusCode::GATEWAY_TIMEOUT,
|
||||
AppError::ServiceUnavailableError(_) => StatusCode::SERVICE_UNAVAILABLE,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn message(&self) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<sea_orm::DbErr> for AppError {
|
||||
fn from(err: sea_orm::DbErr) -> Self {
|
||||
AppError::InternalServerError(format!("Database error: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for AppError {
|
||||
fn from(err: anyhow::Error) -> Self {
|
||||
AppError::InternalServerError(format!("Error: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<chrono::ParseError> for AppError {
|
||||
fn from(err: chrono::ParseError) -> Self {
|
||||
AppError::BadRequestError(format!("Date parsing error: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<uuid::Error> for AppError {
|
||||
fn from(err: uuid::Error) -> Self {
|
||||
AppError::BadRequestError(format!("UUID parsing error: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
let status = self.status_code();
|
||||
(
|
||||
status,
|
||||
Json(json!({
|
||||
"message": self.to_string(),
|
||||
"version": env!("CARGO_PKG_VERSION"),
|
||||
})),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T, E = AppError> = std::result::Result<T, E>;
|
||||
use axum::{
|
||||
Json,
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum AppError {
|
||||
ValidationError(String),
|
||||
AuthenticationError(String),
|
||||
AuthorizationError(String),
|
||||
NotFoundError(String),
|
||||
ConflictError(String),
|
||||
InternalServerError(String),
|
||||
BadRequestError(String),
|
||||
ForbiddenError(String),
|
||||
PaymentRequiredError(String),
|
||||
MethodNotAllowedError(String),
|
||||
NotAcceptableError(String),
|
||||
RequestTimeoutError(String),
|
||||
TooManyRequestsError(String),
|
||||
GatewayTimeoutError(String),
|
||||
ServiceUnavailableError(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AppError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
AppError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
|
||||
AppError::AuthenticationError(msg) => {
|
||||
write!(f, "Authentication failed: {}", msg)
|
||||
}
|
||||
AppError::AuthorizationError(msg) => {
|
||||
write!(f, "Authorization failed: {}", msg)
|
||||
}
|
||||
AppError::NotFoundError(msg) => write!(f, "Resource not found: {}", msg),
|
||||
AppError::ConflictError(msg) => write!(f, "Conflict error: {}", msg),
|
||||
AppError::InternalServerError(msg) => {
|
||||
write!(f, "Internal server error: {}", msg)
|
||||
}
|
||||
AppError::BadRequestError(msg) => write!(f, "Bad request: {}", msg),
|
||||
AppError::ForbiddenError(msg) => write!(f, "Forbidden: {}", msg),
|
||||
AppError::PaymentRequiredError(msg) => write!(f, "Payment required: {}", msg),
|
||||
AppError::MethodNotAllowedError(msg) => {
|
||||
write!(f, "Method not allowed: {}", msg)
|
||||
}
|
||||
AppError::NotAcceptableError(msg) => write!(f, "Not acceptable: {}", msg),
|
||||
AppError::RequestTimeoutError(msg) => write!(f, "Request timeout: {}", msg),
|
||||
AppError::TooManyRequestsError(msg) => write!(f, "Too many requests: {}", msg),
|
||||
AppError::GatewayTimeoutError(msg) => write!(f, "Gateway timeout: {}", msg),
|
||||
AppError::ServiceUnavailableError(msg) => {
|
||||
write!(f, "Service unavailable: {}", msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppError {
|
||||
pub fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
AppError::ValidationError(_) => StatusCode::BAD_REQUEST,
|
||||
AppError::AuthenticationError(_) => StatusCode::UNAUTHORIZED,
|
||||
AppError::AuthorizationError(_) => StatusCode::FORBIDDEN,
|
||||
AppError::NotFoundError(_) => StatusCode::NOT_FOUND,
|
||||
AppError::ConflictError(_) => StatusCode::CONFLICT,
|
||||
AppError::InternalServerError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
AppError::BadRequestError(_) => StatusCode::BAD_REQUEST,
|
||||
AppError::ForbiddenError(_) => StatusCode::FORBIDDEN,
|
||||
AppError::PaymentRequiredError(_) => StatusCode::PAYMENT_REQUIRED,
|
||||
AppError::MethodNotAllowedError(_) => StatusCode::METHOD_NOT_ALLOWED,
|
||||
AppError::NotAcceptableError(_) => StatusCode::NOT_ACCEPTABLE,
|
||||
AppError::RequestTimeoutError(_) => StatusCode::REQUEST_TIMEOUT,
|
||||
AppError::TooManyRequestsError(_) => StatusCode::TOO_MANY_REQUESTS,
|
||||
AppError::GatewayTimeoutError(_) => StatusCode::GATEWAY_TIMEOUT,
|
||||
AppError::ServiceUnavailableError(_) => StatusCode::SERVICE_UNAVAILABLE,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn message(&self) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<sea_orm::DbErr> for AppError {
|
||||
fn from(err: sea_orm::DbErr) -> Self {
|
||||
AppError::InternalServerError(format!("Database error: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for AppError {
|
||||
fn from(err: anyhow::Error) -> Self {
|
||||
AppError::InternalServerError(format!("Error: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<chrono::ParseError> for AppError {
|
||||
fn from(err: chrono::ParseError) -> Self {
|
||||
AppError::BadRequestError(format!("Date parsing error: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<uuid::Error> for AppError {
|
||||
fn from(err: uuid::Error) -> Self {
|
||||
AppError::BadRequestError(format!("UUID parsing error: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
let status = self.status_code();
|
||||
(
|
||||
status,
|
||||
Json(json!({
|
||||
"message": self.to_string(),
|
||||
"version": env!("CARGO_PKG_VERSION"),
|
||||
})),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T, E = AppError> = std::result::Result<T, E>;
|
||||
|
||||
Reference in New Issue
Block a user