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(core): Send whole_connector_response even when Connector sends an Error (#9043)
Anurag3aa38bac1b4a
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex 6ec0ff9fe7..41a12f3557 100644--- a/crates/router/src/services/api.rs+++ b/crates/router/src/services/api.rs@@ -127,6 +127,27 @@ pub type BoxedBillingConnectorPaymentsSyncIntegrationInterface<T, Req, Res> =pub type BoxedVaultConnectorIntegrationInterface<T, Req, Res> =BoxedConnectorIntegrationInterface<T, common_types::VaultConnectorFlowData, Req, Res>;+fn store_raw_connector_response_if_required<T, Req, Resp>(+ return_raw_connector_response: Option<bool>,+ router_data: &mut types::RouterData<T, Req, Resp>,+ body: &types::Response,+) -> CustomResult<(), errors::ConnectorError>+where+ T: Clone + Debug + 'static,+ Req: Debug + Clone + 'static,+ Resp: Debug + Clone + 'static,+{+ if return_raw_connector_response == Some(true) {+ let mut decoded = String::from_utf8(body.response.as_ref().to_vec())+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;+ if decoded.starts_with('\u{feff}') {+ decoded = decoded.trim_start_matches('\u{feff}').to_string();+ }+ router_data.raw_connector_response = Some(Secret::new(decoded));+ }+ Ok(())+}+/// Handle the flow by interacting with connector module/// `connector_request` is applicable only in case if the `CallConnectorAction` is `Trigger`/// In other cases, It will be created if required, even if it is not passed@@ -305,17 +326,13 @@ whereval + external_latency}),);- if return_raw_connector_response == Some(true) {- let mut decoded = String::from_utf8(body.response.as_ref().to_vec())- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;- if decoded.starts_with('\u{feff}') {- decoded = decoded- .trim_start_matches('\u{feff}')- .to_string();- }- data.raw_connector_response =- Some(Secret::new(decoded));- }++ store_raw_connector_response_if_required(+ return_raw_connector_response,+ &mut data,+ &body,+ )?;+Ok(data)}Err(err) => {@@ -342,6 +359,12 @@ where)),);+ store_raw_connector_response_if_required(+ return_raw_connector_response,+ &mut router_data,+ &body,+ )?;+let error = match body.status_code {500..=511 => {let error_res = connector_integration