From c05a16f7f21e33348d88a930d13bb8dfa3acf974 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 27 Feb 2026 20:02:18 -0500 Subject: [PATCH] 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 --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index 0f91af9..e56ecdf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1212,6 +1212,21 @@ fn main() -> std::io::Result<()> { .app_data::>>>(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::new(app_data.insight_generator.clone())) .wrap(prometheus.clone()) })