Add JSON error logging for failed request deserialization

Configures a global JsonConfig error handler that logs the method, URI,
and parse error details at WARN level before returning the 400 response.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Cameron
2026-02-27 20:02:18 -05:00
parent 3982c6d6d4
commit c05a16f7f2

View File

@@ -1212,6 +1212,21 @@ fn main() -> std::io::Result<()> {
.app_data::<Data<Mutex<Box<dyn PreviewDao>>>>(Data::new(Mutex::new(Box::new(
preview_dao,
))))
.app_data(
web::JsonConfig::default()
.error_handler(|err, req| {
let detail = err.to_string();
log::warn!(
"JSON parse error on {} {}: {}",
req.method(),
req.uri(),
detail
);
let response = HttpResponse::BadRequest()
.json(serde_json::json!({"error": detail}));
actix_web::error::InternalError::from_response(err, response).into()
}),
)
.app_data::<Data<InsightGenerator>>(Data::new(app_data.insight_generator.clone()))
.wrap(prometheus.clone())
})