From 7f947169feac9d15616cc2b1a2aacdfa80f219bf Mon Sep 17 00:00:00 2001 From: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com> Date: Wed, 26 Jul 2023 19:18:04 +0530 Subject: [PATCH] feat(errors): add `GenericDuplicateError` in`ApiErrorResponse` (#1792) --- crates/router/src/compatibility/stripe/errors.rs | 7 +++++++ crates/router/src/core/errors/api_error_response.rs | 2 ++ crates/router/src/core/errors/transformers.rs | 3 +++ 3 files changed, 12 insertions(+) diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs index feec71a37a..fae1e033cc 100644 --- a/crates/router/src/compatibility/stripe/errors.rs +++ b/crates/router/src/compatibility/stripe/errors.rs @@ -91,6 +91,9 @@ pub enum StripeErrorCode { #[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "{message}")] GenericNotFoundError { message: String }, + #[error(error_type = StripeErrorType::InvalidRequestError, code = "duplicate_resource", message = "{message}")] + GenericDuplicateError { message: String }, + #[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such merchant account")] MerchantAccountNotFound, @@ -411,6 +414,9 @@ impl From for StripeErrorCode { errors::ApiErrorResponse::GenericNotFoundError { message } => { Self::GenericNotFoundError { message } } + errors::ApiErrorResponse::GenericDuplicateError { message } => { + Self::GenericDuplicateError { message } + } // parameter unknown, invalid request error // actually if we type wrong values in address we get this error. Stripe throws parameter unknown. I don't know if stripe is validating email and stuff errors::ApiErrorResponse::InvalidDataFormat { field_name, @@ -607,6 +613,7 @@ impl actix_web::ResponseError for StripeErrorCode { | Self::PaymentIntentMandateInvalid { .. } | Self::PaymentIntentUnexpectedState { .. } | Self::DuplicatePayment { .. } + | Self::GenericDuplicateError { .. } | Self::IncorrectConnectorNameGiven | Self::ResourceMissing { .. } | Self::FileValidationFailed diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rs index 450eb52a94..e659d5b215 100644 --- a/crates/router/src/core/errors/api_error_response.rs +++ b/crates/router/src/core/errors/api_error_response.rs @@ -207,6 +207,8 @@ pub enum ApiErrorResponse { MissingFileContentType, #[error(error_type = ErrorType::InvalidRequestError, code = "HE_05", message = "{message}")] GenericNotFoundError { message: String }, + #[error(error_type = ErrorType::InvalidRequestError, code = "HE_01", message = "{message}")] + GenericDuplicateError { message: String }, #[error(error_type = ErrorType::InvalidRequestError, code = "WE_01", message = "Failed to authenticate the webhook")] WebhookAuthenticationFailed, #[error(error_type = ErrorType::ObjectNotFound, code = "WE_04", message = "Webhook resource not found")] diff --git a/crates/router/src/core/errors/transformers.rs b/crates/router/src/core/errors/transformers.rs index a315240b0d..2d6774a3d0 100644 --- a/crates/router/src/core/errors/transformers.rs +++ b/crates/router/src/core/errors/transformers.rs @@ -135,6 +135,9 @@ impl ErrorSwitch for ApiErrorRespon Self::DuplicatePayout { payout_id } => { AER::BadRequest(ApiError::new("HE", 1, format!("The payout with the specified payout_id '{payout_id}' already exists in our records"), None)) } + Self::GenericDuplicateError { message } => { + AER::BadRequest(ApiError::new("HE", 1, message, None)) + } Self::RefundNotFound => { AER::NotFound(ApiError::new("HE", 2, "Refund does not exist in our records.", None)) }