Skip to content

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

fix(connector): [Paypal] send valid error_reason in all the error responses (#1914)

Sai Harsha Vardhan3df944196f71
diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rs
index ae1777279c..fa92b233f4 100644
--- a/crates/router/src/connector/paypal.rs
+++ b/crates/router/src/connector/paypal.rs
@@ -77,8 +77,8 @@ impl Paypal {
.parse_struct("Paypal ErrorResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- let error_reason = match response.details {
- Some(order_errors) => order_errors
+ let error_reason = response.details.map(|order_errors| {
+ order_errors
.iter()
.map(|error| {
let mut reason = format!("description - {}", error.description);
@@ -95,14 +95,13 @@ impl Paypal {
reason.push(';');
reason
})
- .collect::<String>(),
- None => consts::NO_ERROR_MESSAGE.to_string(),
- };
+ .collect::<String>()
+ });
Ok(ErrorResponse {
status_code: res.status_code,
code: response.name,
- message: response.message,
- reason: Some(error_reason),
+ message: response.message.clone(),
+ reason: error_reason.or(Some(response.message)),
})
}
}
@@ -178,18 +177,17 @@ impl ConnectorCommon for Paypal {
.parse_struct("Paypal ErrorResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- let error_reason = match response.details {
- Some(error_details) => error_details
+ let error_reason = response.details.map(|error_details| {
+ error_details
.iter()
.map(|error| format!("description - {} ; ", error.description))
- .collect::<String>(),
- None => consts::NO_ERROR_MESSAGE.to_string(),
- };
+ .collect::<String>()
+ });
Ok(ErrorResponse {
status_code: res.status_code,
code: response.name,
- message: response.message,
- reason: Some(error_reason),
+ message: response.message.clone(),
+ reason: error_reason.or(Some(response.message)),
})
}
}
@@ -306,8 +304,8 @@ impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, t
Ok(ErrorResponse {
status_code: res.status_code,
code: response.error,
- message: response.error_description,
- reason: None,
+ message: response.error_description.clone(),
+ reason: Some(response.error_description),
})
}
}