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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(core): Align UCS connector timeout handling with Hyperswitch direct connector timeout response (#13497)
Shubhodip pal7d60e0ceb2bf
diff --git a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rsindex 9cd7e3a946..5899dc0221 100644--- a/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs+++ b/crates/hyperswitch_interfaces/src/unified_connector_service/transformers.rs@@ -24,6 +24,11 @@ use crate::{/// UCS error code indicating the connector returned a 4xx/5xx HTTP response (with `http_status_code` set).const CONNECTOR_ERROR_RESPONSE_CODE: &str = "CONNECTOR_ERROR_RESPONSE";+// Synthetic timeout status used when UCS reports a connector-side timeout over gRPC.+// No connector HTTP response is available in this path; this keeps UCS aligned with+// direct connector timeout handling.+const CONNECTOR_TIMEOUT_HTTP_STATUS_CODE: u16 = 504;+/// Unified Connector Service error variants#[derive(Debug, Clone, thiserror::Error)]pub enum UnifiedConnectorServiceError {@@ -102,8 +107,10 @@ pub enum UnifiedConnectorServiceError {message: String,},- /// Connector error received through UCS (contains original connector HTTP status code).- /// Distinguishes connector errors from UCS errors by presence of status_code.+ /// Connector error received through UCS.+ /// For connector HTTP errors, this contains the original connector HTTP status code.+ /// For connector timeout errors without a connector HTTP response, this contains the+ /// synthetic timeout status used by Hyperswitch.#[error("Connector error via UCS: {0:?}")]ConnectorError(Box<ConnectorErrorInner>),@@ -236,7 +243,8 @@ pub struct ConnectorErrorInner {pub code: String,/// Connector error messagepub message: String,- /// Original HTTP status code from connector+ /// Connector HTTP status code, or the synthetic timeout status when no connector HTTP+ /// response was received.pub status_code: u16,/// Optional reason for the errorpub reason: Option<String>,@@ -1143,6 +1151,10 @@ impl UnifiedConnectorServiceError {return error_from_details;}+ if let Some(timeout_error) = Self::decode_connector_timeout(status, connector_name) {+ return timeout_error;+ }+Self::TonicStatus {code: status.code(),message: status.message().to_string(),@@ -1217,6 +1229,26 @@ impl UnifiedConnectorServiceError {.and_then(|nd| nd.error_message.clone()),})))}++ fn decode_connector_timeout(status: &tonic::Status, connector_name: &str) -> Option<Self> {+ // UCS maps connector/API client request timeouts to gRPC DeadlineExceeded. The+ // status message is not a stable contract, so rely only on the gRPC code.+ if status.code() != tonic::Code::DeadlineExceeded {+ return None;+ }++ Some(Self::ConnectorError(Box::new(ConnectorErrorInner {+ code: crate::consts::REQUEST_TIMEOUT_ERROR_CODE.to_string(),+ message: crate::consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string(),+ status_code: CONNECTOR_TIMEOUT_HTTP_STATUS_CODE,+ reason: Some(crate::consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string()),+ connector: connector_name.to_string(),+ connector_transaction_id: None,+ network_decline_code: None,+ network_advice_code: None,+ network_error_message: None,+ })))+ }}impl ErrorSwitch<ApiErrorResponse> for UnifiedConnectorServiceError {