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(payment_methods): return appropriate error when basilisk locker token expires (#1517)
Shankar Singh C9969c930a9fc
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rsindex 00460d4cce..a9368b2a0e 100644--- a/crates/router/src/compatibility/stripe/errors.rs+++ b/crates/router/src/compatibility/stripe/errors.rs@@ -203,6 +203,8 @@ pub enum StripeErrorCode {WebhookProcessingError,#[error(error_type = StripeErrorType::InvalidRequestError, code = "payment_method_unactivated", message = "The operation cannot be performed as the payment method used has not been activated. Activate the payment method in the Dashboard, then try again.")]PaymentMethodUnactivated,+ #[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "{entity} expired or invalid")]+ HyperswitchUnprocessableEntity { entity: String },// [#216]: https://github.com/juspay/hyperswitch/issues/216// Implement the remaining stripe error codes@@ -379,6 +381,9 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {param: field_name.to_string(),}}+ errors::ApiErrorResponse::UnprocessableEntity { entity } => {+ Self::HyperswitchUnprocessableEntity { entity }+ }errors::ApiErrorResponse::MissingRequiredFields { field_names } => {// Instead of creating a new error variant in StripeErrorCode for MissingRequiredFields, converted vec<&str> to StringSelf::ParameterMissing {@@ -529,7 +534,9 @@ impl actix_web::ResponseError for StripeErrorCode {match self {Self::Unauthorized => StatusCode::UNAUTHORIZED,Self::InvalidRequestUrl => StatusCode::NOT_FOUND,- Self::ParameterUnknown { .. } => StatusCode::UNPROCESSABLE_ENTITY,+ Self::ParameterUnknown { .. } | Self::HyperswitchUnprocessableEntity { .. } => {+ StatusCode::UNPROCESSABLE_ENTITY+ }Self::ParameterMissing { .. }| Self::RefundAmountExceedsPaymentAmount { .. }| Self::PaymentIntentAuthenticationFailure { .. }diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rsindex edbf2763fb..e77f3ed690 100644--- a/crates/router/src/core/errors/api_error_response.rs+++ b/crates/router/src/core/errors/api_error_response.rs@@ -91,6 +91,8 @@ pub enum ApiErrorResponse {MissingRequiredFields { field_names: Vec<&'static str> },#[error(error_type = ErrorType::InvalidRequestError, code = "IR_22", message = "Access forbidden. Not authorized to access this resource")]AccessForbidden,+ #[error(error_type = ErrorType::InvalidRequestError, code = "IR_23", message = "{entity} expired or invalid")]+ UnprocessableEntity { entity: String },#[error(error_type = ErrorType::ConnectorError, code = "CE_00", message = "{code}: {message}", ignore = "status_code")]ExternalConnectorError {code: String,@@ -341,6 +343,7 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorResponApiError::new("IR", 21, "Missing required params".to_string(), Some(Extra {data: Some(serde_json::json!(field_names)), ..Default::default() })),),Self::AccessForbidden => AER::ForbiddenCommonResource(ApiError::new("IR", 22, "Access forbidden. Not authorized to access this resource", None)),+ Self::UnprocessableEntity {entity} => AER::Unprocessable(ApiError::new("IR", 23, format!("{entity} expired or invalid"), None)),Self::ExternalConnectorError {code,message,diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rsindex 24119c895c..57fa3a71a8 100644--- a/crates/router/src/core/payment_methods/vault.rs+++ b/crates/router/src/core/payment_methods/vault.rs@@ -630,9 +630,15 @@ pub async fn get_tokenized_data(}Err(err) => {metrics::TEMP_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);- Err(errors::ApiErrorResponse::InternalServerError)- .into_report()- .attach_printable(format!("Got 4xx from the basilisk locker: {err:?}"))+ match err.status_code {+ 404 => Err(errors::ApiErrorResponse::UnprocessableEntity {+ entity: "Token".to_string(),+ }+ .into()),+ _ => Err(errors::ApiErrorResponse::InternalServerError)+ .into_report()+ .attach_printable(format!("Got error from the basilisk locker: {err:?}")),+ }}}}