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(ucs): Add missing error mapping in HS <> UCS (#13597)

Shubhodip pal577b23a984fb
diff --git a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
index 5899dc0221..adbc0b64bf 100644
--- a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
+++ b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs
@@ -1111,11 +1111,16 @@ impl UnifiedConnectorServiceError {
/// Converts tonic::Code to HTTP status code.
pub fn tonic_to_http_status(code: tonic::Code) -> u16 {
match code {
- tonic::Code::InvalidArgument | tonic::Code::FailedPrecondition => 400,
+ tonic::Code::Cancelled => 408,
+ tonic::Code::InvalidArgument => 400,
tonic::Code::Unauthenticated => 401,
tonic::Code::PermissionDenied => 403,
tonic::Code::NotFound => 404,
tonic::Code::AlreadyExists => 409,
+ tonic::Code::ResourceExhausted => 429,
+ tonic::Code::FailedPrecondition => 412,
+ tonic::Code::Aborted => 409,
+ tonic::Code::OutOfRange => 416,
tonic::Code::Unimplemented => 501,
tonic::Code::Unavailable => 503,
tonic::Code::DeadlineExceeded => 504,
@@ -1123,6 +1128,16 @@ impl UnifiedConnectorServiceError {
}
}
+ fn tonic_status_is_ucs_server_error(code: tonic::Code) -> bool {
+ matches!(
+ code,
+ tonic::Code::Unknown
+ | tonic::Code::Internal
+ | tonic::Code::Unavailable
+ | tonic::Code::DataLoss
+ )
+ }
+
/// Returns HTTP status code for this error.
pub fn http_status(&self) -> u16 {
match self {
@@ -1293,9 +1308,19 @@ impl ErrorSwitch<ApiErrorResponse> for UnifiedConnectorServiceError {
impl ErrorSwitch<ConnectorError> for UnifiedConnectorServiceError {
fn switch(&self) -> ConnectorError {
match self {
- // UCS validation errors (4xx from tonic) → ProcessingStepFailed with encoded error
- // body so the upstream handler can return the right HTTP status code.
Self::TonicStatus { code, message } => {
+ // UCS/Prism server failures must surface as Hyperswitch 5xx errors, not as
+ // payment authorization failures with a nested 5xx payload.
+ if Self::tonic_status_is_ucs_server_error(*code) {
+ return ConnectorError::ResponseHandlingFailed;
+ }
+
+ if *code == tonic::Code::Unimplemented {
+ return ConnectorError::NotImplemented(message.clone());
+ }
+
+ // UCS validation/client-class errors keep the encoded payload for callers that
+ // already rely on structured processing-step data.
let status_code = Self::tonic_to_http_status(*code);
let error_body = serde_json::json!({
"code": format!("UCS_{}", status_code),