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
refactor: Centralize timeout error constants and improve refund error handling (#11073)
Hrithikesh69f7fdcb91e7
diff --git a/crates/pm_auth/src/consts.rs b/crates/pm_auth/src/consts.rsindex dac3485ec8..dd7c5dae46 100644--- a/crates/pm_auth/src/consts.rs+++ b/crates/pm_auth/src/consts.rs@@ -1,5 +1,3 @@pub const REQUEST_TIME_OUT: u64 = 30; // will timeout after the mentioned limit-pub const REQUEST_TIMEOUT_ERROR_CODE: &str = "TIMEOUT"; // timeout error code-pub const REQUEST_TIMEOUT_ERROR_MESSAGE: &str = "Connector did not respond in specified time"; // error message for timed out requestpub const NO_ERROR_CODE: &str = "No error code";pub const NO_ERROR_MESSAGE: &str = "No error message";diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rsindex 23c94087f8..28bed1ff09 100644--- a/crates/router/src/consts.rs+++ b/crates/router/src/consts.rs@@ -26,8 +26,6 @@ pub(crate) const ALPHABETS: [char; 62] = [];/// API client request timeout (in seconds)pub const REQUEST_TIME_OUT: u64 = 30;-pub const REQUEST_TIMEOUT_ERROR_CODE: &str = "TIMEOUT";-pub const REQUEST_TIMEOUT_ERROR_MESSAGE: &str = "Connector did not respond in specified time";pub const REQUEST_TIMEOUT_PAYMENT_NOT_FOUND: &str = "Timed out ,payment not found";pub const REQUEST_TIMEOUT_ERROR_MESSAGE_FROM_PSYNC: &str ="This Payment has been moved to failed as there is no response from the connector";diff --git a/crates/router/src/core/payment_methods/access_token.rs b/crates/router/src/core/payment_methods/access_token.rsindex 0021fbd125..9726a4c838 100644--- a/crates/router/src/core/payment_methods/access_token.rs+++ b/crates/router/src/core/payment_methods/access_token.rs@@ -1,9 +1,9 @@use common_utils::ext_traits::AsyncExt;use error_stack::ResultExt;use hyperswitch_domain_models::types::VaultRouterData;+use hyperswitch_interfaces::consts;use crate::{- consts,core::{errors::{self, RouterResult},payments,diff --git a/crates/router/src/core/payments/access_token.rs b/crates/router/src/core/payments/access_token.rsindex b5931f5c44..463593d802 100644--- a/crates/router/src/core/payments/access_token.rs+++ b/crates/router/src/core/payments/access_token.rs@@ -2,7 +2,10 @@ use std::fmt::Debug;use common_utils::ext_traits::AsyncExt;use error_stack::ResultExt;-use hyperswitch_interfaces::api::{gateway, ConnectorAccessTokenSuffix, ConnectorSpecifications};+use hyperswitch_interfaces::{+ api::{gateway, ConnectorAccessTokenSuffix, ConnectorSpecifications},+ consts as interfaces_consts,+};use crate::{consts,@@ -302,9 +305,9 @@ pub async fn refresh_connector_auth(// further payment flow will not be continuedif connector_error.current_context().is_connector_timeout() {let error_response = types::ErrorResponse {- code: consts::REQUEST_TIMEOUT_ERROR_CODE.to_string(),- message: consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string(),- reason: Some(consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string()),+ code: interfaces_consts::REQUEST_TIMEOUT_ERROR_CODE.to_string(),+ message: interfaces_consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string(),+ reason: Some(interfaces_consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string()),status_code: 504,attempt_status: None,connector_transaction_id: None,@@ -395,9 +398,9 @@ pub async fn execute_authentication_token<// Handle timeout errorsif connector_error.current_context().is_connector_timeout() {let error_response = types::ErrorResponse {- code: consts::REQUEST_TIMEOUT_ERROR_CODE.to_string(),- message: consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string(),- reason: Some(consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string()),+ code: interfaces_consts::REQUEST_TIMEOUT_ERROR_CODE.to_string(),+ message: interfaces_consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string(),+ reason: Some(interfaces_consts::REQUEST_TIMEOUT_ERROR_MESSAGE.to_string()),status_code: 504,attempt_status: None,connector_transaction_id: None,diff --git a/crates/router/src/core/payouts/access_token.rs b/crates/router/src/core/payouts/access_token.rsindex ad7775a88a..ca16ff6549 100644--- a/crates/router/src/core/payouts/access_token.rs+++ b/crates/router/src/core/payouts/access_token.rs@@ -1,9 +1,11 @@use common_utils::ext_traits::AsyncExt;use error_stack::ResultExt;-use hyperswitch_interfaces::api::{ConnectorAccessTokenSuffix, ConnectorCommon};+use hyperswitch_interfaces::{+ api::{ConnectorAccessTokenSuffix, ConnectorCommon},+ consts,+};use crate::{- consts,core::{errors::{self, RouterResult},payments,diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rsindex 9150263d43..19b87fdd4f 100644--- a/crates/router/src/core/refunds.rs+++ b/crates/router/src/core/refunds.rs@@ -13,7 +13,10 @@ use error_stack::{report, ResultExt};use hyperswitch_domain_models::{router_data::ErrorResponse, router_request_types::SplitRefundsRequest,};-use hyperswitch_interfaces::integrity::{CheckIntegrity, FlowIntegrity, GetIntegrityObject};+use hyperswitch_interfaces::{+ consts as interfaces_consts,+ integrity::{CheckIntegrity, FlowIntegrity, GetIntegrityObject},+};use router_env::{instrument, tracing, tracing::Instrument};use scheduler::{consumer::types::process_data, errors as sch_errors, utils as process_tracker_utils,@@ -357,10 +360,26 @@ pub async fn trigger_refund_to_gateway()};+ let refund_status = match err.status_code {+ // If status code is 5xx, we do not change the refund status here+ 500..=511 => None,+ // For other errors, we mark the refund as Failure, since these are definite failures+ _ => Some(enums::RefundStatus::Failure),+ };++ let (refund_error_message, refund_error_code) =+ if err.code == interfaces_consts::REQUEST_TIMEOUT_ERROR_CODE {+ // In case of timeout, we don't have specific error code/message from connector+ // So we don't update those fields in the refund record+ (None, None)+ } else {+ (err.reason.or(Some(err.message)), Some(err.code))+ };+diesel_refund::RefundUpdate::ErrorUpdate {- refund_status: Some(enums::RefundStatus::Failure),- refund_error_message: err.reason.or(Some(err.message)),- refund_error_code: Some(err.code),+ refund_status,+ refund_error_message,+ refund_error_code,updated_by: storage_scheme.to_string(),connector_refund_id: None,processor_refund_data: None,@@ -963,10 +982,21 @@ pub async fn sync_refund_with_gateway(200..=299 => Some(enums::RefundStatus::Failure),_ => None,};+ let (refund_error_message, refund_error_code) =+ if error_message.code == interfaces_consts::REQUEST_TIMEOUT_ERROR_CODE {+ // In case of timeout, we don't have specific error code/message from connector+ // So we don't update those fields in the refund record+ (None, None)+ } else {+ (+ error_message.reason.or(Some(error_message.message)),+ Some(error_message.code),+ )+ };diesel_refund::RefundUpdate::ErrorUpdate {refund_status,- refund_error_message: error_message.reason.or(Some(error_message.message)),- refund_error_code: Some(error_message.code),+ refund_error_message,+ refund_error_code,updated_by: storage_scheme.to_string(),connector_refund_id: None,processor_refund_data: None,diff --git a/crates/router/src/services/pm_auth.rs b/crates/router/src/services/pm_auth.rsindex 2d8097037d..1190ee4eef 100644--- a/crates/router/src/services/pm_auth.rs+++ b/crates/router/src/services/pm_auth.rs@@ -1,5 +1,5 @@+use hyperswitch_interfaces::consts;use pm_auth::{- consts,core::errors::ConnectorError,types::{self as pm_auth_types, api::BoxedConnectorIntegration, PaymentAuthRouterData},};