mirror of
https://github.com/juspay/hyperswitch.git
synced 2026-03-13 09:02:06 +08:00
refactor: Centralize timeout error constants and improve refund error handling (#11073)
This commit is contained in:
@@ -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 request
|
||||
pub const NO_ERROR_CODE: &str = "No error code";
|
||||
pub const NO_ERROR_MESSAGE: &str = "No error message";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 continued
|
||||
if 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 errors
|
||||
if 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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use hyperswitch_interfaces::consts;
|
||||
use pm_auth::{
|
||||
consts,
|
||||
core::errors::ConnectorError,
|
||||
types::{self as pm_auth_types, api::BoxedConnectorIntegration, PaymentAuthRouterData},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user