Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(router): handle empty body parse failures in bad request logger middleware (#3541)
Sai Harsha Vardhanbe22d60ddac1
diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rsindex 1c80aff439..ed443c9e41 100644--- a/crates/router/src/lib.rs+++ b/crates/router/src/lib.rs@@ -258,8 +258,8 @@ pub fn get_application_builder(.wrap(middleware::default_response_headers()).wrap(middleware::RequestId).wrap(cors::cors())- .wrap(middleware::LogSpanInitializer)// this middleware works only for Http1.1 requests.wrap(middleware::Http400RequestDetailsLogger)+ .wrap(middleware::LogSpanInitializer).wrap(router_env::tracing_actix_web::TracingLogger::default())}diff --git a/crates/router/src/middleware.rs b/crates/router/src/middleware.rsindex 9205f53a04..6f3427bf7a 100644--- a/crates/router/src/middleware.rs+++ b/crates/router/src/middleware.rs@@ -258,13 +258,24 @@ wherelet response = response_fut.await?;// Log the request_details when we receive 400 status from the applicationif response.status() == 400 {- let value: serde_json::Value = serde_json::from_slice(&bytes)?;let request_id = request_id_fut.await?.as_hyphenated().to_string();- logger::info!(- "request_id: {}, request_details: {}",- request_id,- get_request_details_from_value(&value, "")- );+ if !bytes.is_empty() {+ let value_result: Result<serde_json::Value, serde_json::Error> =+ serde_json::from_slice(&bytes);+ match value_result {+ Ok(value) => {+ logger::info!(+ "request_id: {request_id}, request_details: {}",+ get_request_details_from_value(&value, "")+ );+ }+ Err(err) => {+ logger::warn!("error while parsing the request in json value: {err}");+ }+ }+ } else {+ logger::info!("request_id: {request_id}, request_details: Empty Body");+ }}Ok(response)})