refactor(mandates): refactor mandates to check for misleading error codes in mandates (#1377)

This commit is contained in:
BallaNitesh
2023-06-27 15:52:27 +05:30
committed by GitHub
parent 784847b08c
commit a899c97389
5 changed files with 14 additions and 8 deletions

View File

@ -421,6 +421,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
errors::ApiErrorResponse::RefundFailed { data } => Self::RefundFailed, // Nothing at stripe to map errors::ApiErrorResponse::RefundFailed { data } => Self::RefundFailed, // Nothing at stripe to map
errors::ApiErrorResponse::MandateUpdateFailed errors::ApiErrorResponse::MandateUpdateFailed
| errors::ApiErrorResponse::MandateSerializationFailed
| errors::ApiErrorResponse::MandateDeserializationFailed
| errors::ApiErrorResponse::InternalServerError => Self::InternalServerError, // not a stripe code | errors::ApiErrorResponse::InternalServerError => Self::InternalServerError, // not a stripe code
errors::ApiErrorResponse::ExternalConnectorError { errors::ApiErrorResponse::ExternalConnectorError {
code, code,

View File

@ -154,6 +154,10 @@ pub enum ApiErrorResponse {
MandateUpdateFailed, MandateUpdateFailed,
#[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "API Key does not exist in our records")] #[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "API Key does not exist in our records")]
ApiKeyNotFound, ApiKeyNotFound,
#[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "Invalid mandate id passed from connector")]
MandateSerializationFailed,
#[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "Unable to parse the mandate identifier passed from connector")]
MandateDeserializationFailed,
#[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "Return URL is not configured and not passed in payments request")] #[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "Return URL is not configured and not passed in payments request")]
ReturnUrlUnavailable, ReturnUrlUnavailable,
#[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "This refund is not possible through Hyperswitch. Please raise the refund through {connector} dashboard")] #[error(error_type = ErrorType::ValidationError, code = "HE_03", message = "This refund is not possible through Hyperswitch. Please raise the refund through {connector} dashboard")]
@ -369,7 +373,7 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
Self::VerificationFailed { data } => { Self::VerificationFailed { data } => {
AER::BadRequest(ApiError::new("CE", 7, "Verification failed while processing with connector. Retry operation", Some(Extra { data: data.clone(), ..Default::default()}))) AER::BadRequest(ApiError::new("CE", 7, "Verification failed while processing with connector. Retry operation", Some(Extra { data: data.clone(), ..Default::default()})))
}, },
Self::MandateUpdateFailed | Self::InternalServerError => { Self::MandateUpdateFailed | Self::MandateSerializationFailed | Self::MandateDeserializationFailed | Self::InternalServerError => {
AER::InternalServerError(ApiError::new("HE", 0, "Something went wrong", None)) AER::InternalServerError(ApiError::new("HE", 0, "Something went wrong", None))
} }
Self::DuplicateRefundRequest => AER::BadRequest(ApiError::new("HE", 1, "Duplicate refund request. Refund already attempted with the refund ID", None)), Self::DuplicateRefundRequest => AER::BadRequest(ApiError::new("HE", 1, "Duplicate refund request. Refund already attempted with the refund ID", None)),

View File

@ -144,7 +144,7 @@ where
.store .store
.find_mandate_by_merchant_id_mandate_id(resp.merchant_id.as_ref(), mandate_id) .find_mandate_by_merchant_id_mandate_id(resp.merchant_id.as_ref(), mandate_id)
.await .await
.change_context(errors::ApiErrorResponse::MandateNotFound)?; .to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?;
let mandate = match mandate.mandate_type { let mandate = match mandate.mandate_type {
storage_enums::MandateType::SingleUse => state storage_enums::MandateType::SingleUse => state
.store .store
@ -197,7 +197,9 @@ where
let mandate_ids = mandate_reference let mandate_ids = mandate_reference
.map(|md| { .map(|md| {
Encode::<types::MandateReference>::encode_to_value(&md) Encode::<types::MandateReference>::encode_to_value(&md)
.change_context(errors::ApiErrorResponse::MandateNotFound) .change_context(
errors::ApiErrorResponse::MandateSerializationFailed,
)
.map(masking::Secret::new) .map(masking::Secret::new)
}) })
.transpose()?; .transpose()?;
@ -224,7 +226,7 @@ where
.parse_value::<api_models::payments::ConnectorMandateReferenceId>( .parse_value::<api_models::payments::ConnectorMandateReferenceId>(
"ConnectorMandateId", "ConnectorMandateId",
) )
.change_context(errors::ApiErrorResponse::MandateNotFound) .change_context(errors::ApiErrorResponse::MandateDeserializationFailed)
}) })
.transpose()? .transpose()?
.map_or( .map_or(

View File

@ -160,7 +160,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
let mandate = db let mandate = db
.find_mandate_by_merchant_id_mandate_id(merchant_id, mandate_id) .find_mandate_by_merchant_id_mandate_id(merchant_id, mandate_id)
.await .await
.change_context(errors::ApiErrorResponse::MandateNotFound); .to_not_found_response(errors::ApiErrorResponse::MandateNotFound);
Some(mandate.and_then(|mandate_obj| { Some(mandate.and_then(|mandate_obj| {
match ( match (
mandate_obj.network_transaction_id, mandate_obj.network_transaction_id,

View File

@ -52,9 +52,7 @@ impl MandateResponseExt for MandateResponse {
&payment_method.payment_method_id, &payment_method.payment_method_id,
merchant_account.locker_id.clone(), merchant_account.locker_id.clone(),
) )
.await .await?;
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error getting card from card vault")?;
let card_detail = payment_methods::transformers::get_card_detail(&payment_method, card) let card_detail = payment_methods::transformers::get_card_detail(&payment_method, card)
.change_context(errors::ApiErrorResponse::InternalServerError) .change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while getting card details")?; .attach_printable("Failed while getting card details")?;