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:
15
src/main.rs
15
src/main.rs
@@ -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())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user