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(core): surface connector error code + http status on UCS connector errors (#13003)

Yashasvi Kapilbb5f225df2d8
diff --git a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
index ddbef3b6e9..8298811fcf 100644
--- a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
+++ b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
@@ -981,7 +981,12 @@ impl UnifiedConnectorServiceError {
let status_code = u16::try_from(connector_error.http_status_code?).ok()?;
Some(Self::ConnectorError(Box::new(ConnectorErrorInner {
- code: connector_error.error_code,
+ code: connector_error
+ .error_info
+ .as_ref()
+ .and_then(|error_info| error_info.connector_details.as_ref())
+ .and_then(|connector_details| connector_details.code.clone())
+ .unwrap_or_else(|| connector_error.error_code.clone()),
message: connector_error.error_message,
status_code,
reason: connector_error
diff --git a/crates/router/src/core/payments/gateway/authorize_gateway.rs b/crates/router/src/core/payments/gateway/authorize_gateway.rs
index 0841c4bc4b..22bea07ba6 100644
--- a/crates/router/src/core/payments/gateway/authorize_gateway.rs
+++ b/crates/router/src/core/payments/gateway/authorize_gateway.rs
@@ -178,6 +178,7 @@ where
network_error_message: network_error_message.clone(),
connector_metadata: None,
});
+ router_data.connector_http_status_code = Some(status_code);
return Ok((
router_data,
(),
@@ -312,6 +313,7 @@ where
// Return Ok with router_data containing the error response
// This ensures the connector error flows through the normal
// response handling path (same as direct connector errors)
+ router_data.connector_http_status_code = Some(status_code);
return Ok((
router_data,
(),
diff --git a/crates/router/src/core/payments/gateway/cancel_gateway.rs b/crates/router/src/core/payments/gateway/cancel_gateway.rs
index b32a1e7c07..2eb73bbdbe 100644
--- a/crates/router/src/core/payments/gateway/cancel_gateway.rs
+++ b/crates/router/src/core/payments/gateway/cancel_gateway.rs
@@ -153,6 +153,7 @@ where
connector_metadata: None,
},
);
+ router_data.connector_http_status_code = Some(status_code);
return Ok((
router_data,
(),
diff --git a/crates/router/src/core/payments/gateway/capture_gateway.rs b/crates/router/src/core/payments/gateway/capture_gateway.rs
index d4d5c08e24..a4c08c19cb 100644
--- a/crates/router/src/core/payments/gateway/capture_gateway.rs
+++ b/crates/router/src/core/payments/gateway/capture_gateway.rs
@@ -155,6 +155,7 @@ where
connector_metadata: None,
},
);
+ router_data.connector_http_status_code = Some(status_code);
return Ok((
router_data,
(),
diff --git a/crates/router/src/core/payments/gateway/psync_gateway.rs b/crates/router/src/core/payments/gateway/psync_gateway.rs
index 5328fc2afc..4d351da1e9 100644
--- a/crates/router/src/core/payments/gateway/psync_gateway.rs
+++ b/crates/router/src/core/payments/gateway/psync_gateway.rs
@@ -233,6 +233,7 @@ where
connector_metadata: None,
},
);
+ router_data.connector_http_status_code = Some(status_code);
return Ok((
router_data,
(),
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index 8c24d2b7f0..1802c4d8b2 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -3120,6 +3120,7 @@ pub async fn call_unified_connector_service_for_refund_execute(
network_error_message: network_error_message.clone(),
connector_metadata: None,
});
+ router_data.connector_http_status_code = Some(status_code);
return Ok((router_data, (), payments_grpc::RefundResponse::default()));
}
let api_error = report.current_context().switch();
@@ -3255,6 +3256,7 @@ pub async fn call_unified_connector_service_for_refund_sync(
network_error_message: network_error_message.clone(),
connector_metadata: None,
});
+ router_data.connector_http_status_code = Some(status_code);
return Ok((router_data, (), payments_grpc::RefundResponse::default()));
}
let api_error = report.current_context().switch();