feat: add tracing throughout, HTTP TraceLayer, detailed error logs

This commit is contained in:
2026-07-11 21:58:58 +02:00
parent e89cf48b34
commit 2b702d88e4
11 changed files with 60 additions and 13 deletions

View File

@@ -5,11 +5,20 @@ use domain::DomainError;
pub fn map_error(e: DomainError) -> (StatusCode, Json<ErrorResponse>) {
let (status, message) = match &e {
DomainError::NotFound => (StatusCode::NOT_FOUND, "not found".to_string()),
DomainError::ValidationError(msg) => (StatusCode::BAD_REQUEST, msg.clone()),
DomainError::Unauthorized(msg) => (StatusCode::UNAUTHORIZED, msg.clone()),
DomainError::Forbidden(msg) => (StatusCode::FORBIDDEN, msg.clone()),
DomainError::InfrastructureError(_) => {
tracing::error!("{e}");
DomainError::ValidationError(msg) => {
tracing::debug!(error = msg, "validation error");
(StatusCode::BAD_REQUEST, msg.clone())
}
DomainError::Unauthorized(msg) => {
tracing::debug!(error = msg, "unauthorized");
(StatusCode::UNAUTHORIZED, msg.clone())
}
DomainError::Forbidden(msg) => {
tracing::warn!(error = msg, "forbidden");
(StatusCode::FORBIDDEN, msg.clone())
}
DomainError::InfrastructureError(detail) => {
tracing::error!(error = detail, "infrastructure error");
(
StatusCode::INTERNAL_SERVER_ERROR,
"internal error".to_string(),

View File

@@ -10,6 +10,7 @@ use axum::{
use infra_wiring::CorsOrigins;
use tower_http::cors::{Any, CorsLayer};
use tower_http::services::{ServeDir, ServeFile};
use tower_http::trace::TraceLayer;
use crate::state::AppState;
@@ -37,6 +38,7 @@ pub fn build_router(state: AppState) -> Router<()> {
Router::new()
.nest("/api", api)
.fallback_service(spa_service)
.layer(TraceLayer::new_for_http())
.layer(cors)
.with_state(state)
}