From da77d1393b8f6ab658dd7f3c202dd6c7d15c0ebd Mon Sep 17 00:00:00 2001 From: chikke srujan <121822803+srujanchikke@users.noreply.github.com> Date: Wed, 18 Oct 2023 14:04:13 +0530 Subject: [PATCH] fix(connector): [Paypal]fix error deserelization for source verification call (#2611) --- crates/router/src/connector/paypal.rs | 19 ++++++++++++------- .../src/connector/paypal/transformers.rs | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rs index a0a787269e37..4a1689338fd6 100644 --- a/crates/router/src/connector/paypal.rs +++ b/crates/router/src/connector/paypal.rs @@ -174,26 +174,31 @@ impl ConnectorCommon for Paypal { .map(|error_details| { error_details .iter() - .try_fold::<_, _, CustomResult<_, errors::ConnectorError>>( - String::new(), - |mut acc, error| { - write!(acc, "description - {} ;", error.description) + .try_fold(String::new(), |mut acc, error| { + if let Some(description) = &error.description { + write!(acc, "description - {} ;", description) .into_report() .change_context( errors::ConnectorError::ResponseDeserializationFailed, ) .attach_printable("Failed to concatenate error details") .map(|_| acc) - }, - ) + } else { + Ok(acc) + } + }) }) .transpose()?; + let reason = error_reason + .unwrap_or(response.message.to_owned()) + .is_empty() + .then_some(response.message.to_owned()); Ok(ErrorResponse { status_code: res.status_code, code: response.name, message: response.message.clone(), - reason: error_reason.or(Some(response.message)), + reason, }) } } diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rs index 72dccaed7332..927c33277ab9 100644 --- a/crates/router/src/connector/paypal/transformers.rs +++ b/crates/router/src/connector/paypal/transformers.rs @@ -1380,7 +1380,7 @@ pub struct PaypalOrderErrorResponse { #[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct ErrorDetails { pub issue: String, - pub description: String, + pub description: Option, } #[derive(Default, Debug, Serialize, Deserialize, PartialEq)]