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: [WORLDPAY] Handle text/html 404 responses gracefully (#8753)
Venkatesh277884729b2e
diff --git a/crates/hyperswitch_connectors/src/connectors/worldpay.rs b/crates/hyperswitch_connectors/src/connectors/worldpay.rsindex 5996115acd..8a8560fa19 100644--- a/crates/hyperswitch_connectors/src/connectors/worldpay.rs+++ b/crates/hyperswitch_connectors/src/connectors/worldpay.rs@@ -82,8 +82,8 @@ use crate::{constants::headers,types::ResponseRouterData,utils::{- convert_amount, get_header_key_value, is_mandate_supported, ForeignTryFrom,- PaymentMethodDataType, RefundsRequestData,+ convert_amount, get_header_key_value, is_html_response_from_headers, is_mandate_supported,+ ForeignTryFrom, PaymentMethodDataType, RefundsRequestData,},};@@ -164,9 +164,21 @@ impl ConnectorCommon for Worldpay {event_builder: Option<&mut ConnectorEvent>,) -> CustomResult<ErrorResponse, errors::ConnectorError> {let response = if !res.response.is_empty() {- res.response- .parse_struct("WorldpayErrorResponse")- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?+ // Check if the response is HTML (likely a 404 error from Worldpay)+ if is_html_response_from_headers(res.headers.as_ref()) {+ // Log the HTML body for debugging purposes (contains RequestID and other details)+ router_env::logger::info!(+ "Worldpay returned HTML response: status_code={}, body={}",+ res.status_code,+ String::from_utf8_lossy(&res.response)+ );+ // For HTML responses (like 404), create a default error response+ WorldpayErrorResponse::default(res.status_code)+ } else {+ res.response+ .parse_struct("WorldpayErrorResponse")+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?+ }} else {WorldpayErrorResponse::default(res.status_code)};@@ -480,9 +492,21 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Worevent_builder: Option<&mut ConnectorEvent>,) -> CustomResult<ErrorResponse, errors::ConnectorError> {let response = if !res.response.is_empty() {- res.response- .parse_struct("WorldpayErrorResponse")- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?+ // Check if the response is HTML (likely a 404 error from Worldpay)+ if is_html_response_from_headers(res.headers.as_ref()) {+ // Log the HTML body for debugging purposes (contains RequestID and other details)+ router_env::logger::info!(+ "Worldpay returned HTML response: status_code={}, body={}",+ res.status_code,+ String::from_utf8_lossy(&res.response)+ );+ // For HTML responses (like 404), create a default error response+ WorldpayErrorResponse::default(res.status_code)+ } else {+ res.response+ .parse_struct("WorldpayErrorResponse")+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?+ }} else {WorldpayErrorResponse::default(res.status_code)};diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rsindex f4d5fcb348..9ff55ae80a 100644--- a/crates/hyperswitch_connectors/src/utils.rs+++ b/crates/hyperswitch_connectors/src/utils.rs@@ -6835,6 +6835,16 @@ pub fn is_html_response(response: &str) -> bool {|| response.starts_with("<!doctype html>")}+pub fn is_html_response_from_headers(headers: Option<&http::HeaderMap>) -> bool {+ headers+ .and_then(|headers| headers.get(http::header::CONTENT_TYPE))+ .and_then(|content_type| content_type.to_str().ok())+ .map(|content_type| {+ content_type.contains("text/html") || content_type.contains("application/xhtml+xml")+ })+ .unwrap_or(false)+}+#[cfg(feature = "payouts")]pub trait PayoutsData {fn get_transfer_id(&self) -> Result<String, Error>;