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
fix(connector): [iatapay]handle empty error response in case of 401 (#4291)
chikke srujand1404d9aff2a
diff --git a/crates/router/src/connector/iatapay.rs b/crates/router/src/connector/iatapay.rsindex 9adf50d6f5..f4debb1403 100644--- a/crates/router/src/connector/iatapay.rs+++ b/crates/router/src/connector/iatapay.rs@@ -116,22 +116,33 @@ impl ConnectorCommon for Iatapay {res: Response,event_builder: Option<&mut ConnectorEvent>,) -> CustomResult<ErrorResponse, errors::ConnectorError> {- let response: iatapay::IatapayErrorResponse = res- .response- .parse_struct("IatapayErrorResponse")- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;-- event_builder.map(|i| i.set_error_response_body(&response));- router_env::logger::info!(connector_response=?response);-- Ok(ErrorResponse {- status_code: res.status_code,- code: response.error,- message: response.message,- reason: response.reason,- attempt_status: None,- connector_transaction_id: None,- })+ let response_error_message = if res.response.is_empty() && res.status_code == 401 {+ ErrorResponse {+ status_code: res.status_code,+ code: consts::NO_ERROR_CODE.to_string(),+ message: consts::NO_ERROR_MESSAGE.to_string(),+ reason: Some(consts::CONNECTOR_UNAUTHORIZED_ERROR.to_string()),+ attempt_status: None,+ connector_transaction_id: None,+ }+ } else {+ let response: iatapay::IatapayErrorResponse = res+ .response+ .parse_struct("IatapayErrorResponse")+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;++ event_builder.map(|i| i.set_error_response_body(&response));+ router_env::logger::info!(connector_response=?response);+ ErrorResponse {+ status_code: res.status_code,+ code: response.error,+ message: response.message,+ reason: response.reason,+ attempt_status: None,+ connector_transaction_id: None,+ }+ };+ Ok(response_error_message)}}@@ -245,8 +256,8 @@ impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, tOk(ErrorResponse {status_code: res.status_code,- code: response.error,- message: response.path,+ code: response.error.clone(),+ message: response.path.unwrap_or(response.error),reason: None,attempt_status: None,connector_transaction_id: None,diff --git a/crates/router/src/connector/iatapay/transformers.rs b/crates/router/src/connector/iatapay/transformers.rsindex bce25a7642..3e337d3a74 100644--- a/crates/router/src/connector/iatapay/transformers.rs+++ b/crates/router/src/connector/iatapay/transformers.rs@@ -503,7 +503,7 @@ pub struct IatapayErrorResponse {#[derive(Deserialize, Debug, Serialize)]pub struct IatapayAccessTokenErrorResponse {pub error: String,- pub path: String,+ pub path: Option<String>,}#[derive(Debug, Serialize, Deserialize)]diff --git a/crates/router/src/core/payments/access_token.rs b/crates/router/src/core/payments/access_token.rsindex f7fe5b7844..2d4ed2b6e1 100644--- a/crates/router/src/core/payments/access_token.rs+++ b/crates/router/src/core/payments/access_token.rs@@ -83,7 +83,16 @@ pub async fn add_access_token<.attach_printable("DB error when accessing the access token")?;let res = match old_access_token {- Some(access_token) => Ok(Some(access_token)),+ Some(access_token) => {+ router_env::logger::debug!(+ "Access token found in redis for merchant_id: {}, payment_id: {}, connector: {} which has expiry of: {} seconds",+ merchant_account.merchant_id,+ router_data.payment_id,+ connector.connector_name,+ access_token.expires+ );+ Ok(Some(access_token))+ }None => {let cloned_router_data = router_data.clone();let refresh_token_request_data = types::AccessTokenRequestData::try_from(diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rsindex 5dbfff8342..00db8fb29d 100644--- a/crates/router/src/workflows/payment_sync.rs+++ b/crates/router/src/workflows/payment_sync.rs@@ -127,7 +127,7 @@ impl ProcessTrackerWorkflow<AppState> for PaymentsSyncWorkflow {let payment_attempt_update =hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ErrorUpdate {connector: None,- status: api_models::enums::AttemptStatus::AuthenticationFailed,+ status: api_models::enums::AttemptStatus::Failure,error_code: None,error_message: None,error_reason: Some(Some(