fix(connector): [iatapay]handle empty error response in case of 401 (#4291)

Signed-off-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
Co-authored-by: AkshayaFoiger <131388445+AkshayaFoiger@users.noreply.github.com>
Co-authored-by: AkshayaFoiger <akshaya.shankar@juspay.in>
This commit is contained in:
chikke srujan
2024-05-09 18:29:46 +05:30
committed by GitHub
parent f386f423c0
commit d1404d9aff
4 changed files with 40 additions and 20 deletions

View File

@ -116,22 +116,33 @@ impl ConnectorCommon for Iatapay {
res: Response, res: Response,
event_builder: Option<&mut ConnectorEvent>, event_builder: Option<&mut ConnectorEvent>,
) -> CustomResult<ErrorResponse, errors::ConnectorError> { ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
let response: iatapay::IatapayErrorResponse = res let response_error_message = if res.response.is_empty() && res.status_code == 401 {
.response ErrorResponse {
.parse_struct("IatapayErrorResponse") status_code: res.status_code,
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?; 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)); event_builder.map(|i| i.set_error_response_body(&response));
router_env::logger::info!(connector_response=?response); router_env::logger::info!(connector_response=?response);
ErrorResponse {
Ok(ErrorResponse { status_code: res.status_code,
status_code: res.status_code, code: response.error,
code: response.error, message: response.message,
message: response.message, reason: response.reason,
reason: response.reason, attempt_status: None,
attempt_status: None, connector_transaction_id: None,
connector_transaction_id: None, }
}) };
Ok(response_error_message)
} }
} }
@ -245,8 +256,8 @@ impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, t
Ok(ErrorResponse { Ok(ErrorResponse {
status_code: res.status_code, status_code: res.status_code,
code: response.error, code: response.error.clone(),
message: response.path, message: response.path.unwrap_or(response.error),
reason: None, reason: None,
attempt_status: None, attempt_status: None,
connector_transaction_id: None, connector_transaction_id: None,

View File

@ -503,7 +503,7 @@ pub struct IatapayErrorResponse {
#[derive(Deserialize, Debug, Serialize)] #[derive(Deserialize, Debug, Serialize)]
pub struct IatapayAccessTokenErrorResponse { pub struct IatapayAccessTokenErrorResponse {
pub error: String, pub error: String,
pub path: String, pub path: Option<String>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

View File

@ -83,7 +83,16 @@ pub async fn add_access_token<
.attach_printable("DB error when accessing the access token")?; .attach_printable("DB error when accessing the access token")?;
let res = match old_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 => { None => {
let cloned_router_data = router_data.clone(); let cloned_router_data = router_data.clone();
let refresh_token_request_data = types::AccessTokenRequestData::try_from( let refresh_token_request_data = types::AccessTokenRequestData::try_from(

View File

@ -127,7 +127,7 @@ impl ProcessTrackerWorkflow<AppState> for PaymentsSyncWorkflow {
let payment_attempt_update = let payment_attempt_update =
hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ErrorUpdate { hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ErrorUpdate {
connector: None, connector: None,
status: api_models::enums::AttemptStatus::AuthenticationFailed, status: api_models::enums::AttemptStatus::Failure,
error_code: None, error_code: None,
error_message: None, error_message: None,
error_reason: Some(Some( error_reason: Some(Some(