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

chore(payments): filter NO_ERROR_CODE and NO_ERROR_MESSAGE from payments API response (#7801)

Kashif7b3c33c81c8f
diff --git a/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs b/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs
index f7167a607a..7ce8ed6d71 100644
--- a/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs
@@ -892,11 +892,11 @@ impl<F>
code: non_threeds_data
.error_code
.clone()
- .unwrap_or_else(|| "NO_ERROR_CODE".to_string()),
+ .unwrap_or_else(|| consts::NO_ERROR_CODE.to_string()),
message: non_threeds_data
.error_desc
.clone()
- .unwrap_or_else(|| "NO_ERROR_MESSAGE".to_string()),
+ .unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: non_threeds_data.error_desc.clone(),
status_code: item.http_code,
attempt_status: None,
@@ -941,11 +941,11 @@ impl<F>
code: recurring_response
.reason
.clone()
- .unwrap_or_else(|| "NO_ERROR_CODE".to_string()),
+ .unwrap_or_else(|| consts::NO_ERROR_CODE.to_string()),
message: recurring_response
.reason
.clone()
- .unwrap_or_else(|| "NO_ERROR_MESSAGE".to_string()),
+ .unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: recurring_response.reason.clone(),
status_code: item.http_code,
attempt_status: None,
@@ -1480,19 +1480,17 @@ impl TryFrom<PaymentsCaptureResponseRouterData<PaymentCaptureResponse>>
}?;
let capture_message_status = capture_status_codes();
let error_response = if status == enums::AttemptStatus::Failure {
+ let optional_message = capture_message_status
+ .get(status_code.as_str())
+ .copied()
+ .map(String::from);
Some(ErrorResponse {
status_code: item.http_code,
code: status_code.to_owned(),
- message: capture_message_status
- .get(status_code.as_str())
- .unwrap_or(&"NO_ERROR_MESSAGE")
- .to_string(),
- reason: Some(
- capture_message_status
- .get(status_code.as_str())
- .unwrap_or(&"NO_ERROR_REASON")
- .to_string(),
- ),
+ message: optional_message
+ .clone()
+ .unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
+ reason: optional_message,
attempt_status: None,
connector_transaction_id: Some(item.response.tran_id.clone()),
network_advice_code: None,
@@ -1596,19 +1594,18 @@ impl TryFrom<PaymentsCancelResponseRouterData<FiuuPaymentCancelResponse>>
}?;
let void_message_status = void_status_codes();
let error_response = if status == enums::AttemptStatus::VoidFailed {
+ let optional_message = void_message_status
+ .get(status_code.as_str())
+ .copied()
+ .map(String::from);
+
Some(ErrorResponse {
status_code: item.http_code,
code: status_code.to_owned(),
- message: void_message_status
- .get(status_code.as_str())
- .unwrap_or(&"NO_ERROR_MESSAGE")
- .to_string(),
- reason: Some(
- void_message_status
- .get(status_code.as_str())
- .unwrap_or(&"NO_ERROR_REASON")
- .to_string(),
- ),
+ message: optional_message
+ .clone()
+ .unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
+ reason: optional_message,
attempt_status: None,
connector_transaction_id: Some(item.response.tran_id.clone()),
network_advice_code: None,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 3b6e124329..0628a7281f 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -2107,6 +2107,8 @@ where
{
use std::ops::Not;
+ use hyperswitch_interfaces::consts::{NO_ERROR_CODE, NO_ERROR_MESSAGE};
+
let payment_attempt = payment_data.get_payment_attempt().clone();
let payment_intent = payment_data.get_payment_intent().clone();
let payment_link_data = payment_data.get_payment_link_data();
@@ -2593,10 +2595,13 @@ where
statement_descriptor_suffix: payment_intent.statement_descriptor_suffix,
next_action: next_action_response,
cancellation_reason: payment_attempt.cancellation_reason,
- error_code: payment_attempt.error_code,
+ error_code: payment_attempt
+ .error_code
+ .filter(|code| code != NO_ERROR_CODE),
error_message: payment_attempt
.error_reason
- .or(payment_attempt.error_message),
+ .or(payment_attempt.error_message)
+ .filter(|message| message != NO_ERROR_MESSAGE),
unified_code: payment_attempt.unified_code,
unified_message: payment_attempt.unified_message,
payment_experience: payment_attempt.payment_experience,