Skip to content

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

refactor(router): add the `connector_label` field to `DuplicateMerchantConnectorAccount` error message (#1044)

EliKalterb3772f8ef13a
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs
index 766aadd212..f1099a09da 100644
--- a/crates/router/src/compatibility/stripe/errors.rs
+++ b/crates/router/src/compatibility/stripe/errors.rs
@@ -103,8 +103,8 @@ pub enum StripeErrorCode {
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate merchant account")]
DuplicateMerchantAccount,
- #[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate merchant_connector_account")]
- DuplicateMerchantConnectorAccount,
+ #[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "The merchant connector account with the specified connector_label '{connector_label}' already exists in our records")]
+ DuplicateMerchantConnectorAccount { connector_label: String },
#[error(error_type = StripeErrorType::InvalidRequestError, code = "token_already_used", message = "duplicate payment method")]
DuplicatePaymentMethod,
@@ -438,8 +438,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
}
errors::ApiErrorResponse::ReturnUrlUnavailable => Self::ReturnUrlUnavailable,
errors::ApiErrorResponse::DuplicateMerchantAccount => Self::DuplicateMerchantAccount,
- errors::ApiErrorResponse::DuplicateMerchantConnectorAccount => {
- Self::DuplicateMerchantConnectorAccount
+ errors::ApiErrorResponse::DuplicateMerchantConnectorAccount { connector_label } => {
+ Self::DuplicateMerchantConnectorAccount { connector_label }
}
errors::ApiErrorResponse::DuplicatePaymentMethod => Self::DuplicatePaymentMethod,
errors::ApiErrorResponse::ClientSecretInvalid => Self::PaymentIntentInvalidParameter {
@@ -521,7 +521,7 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::MandateNotFound
| Self::ApiKeyNotFound
| Self::DuplicateMerchantAccount
- | Self::DuplicateMerchantConnectorAccount
+ | Self::DuplicateMerchantConnectorAccount { .. }
| Self::DuplicatePaymentMethod
| Self::PaymentFailed
| Self::VerificationFailed { .. }
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index fbf5180b67..10f60d64c9 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -422,7 +422,11 @@ pub async fn create_payment_connector(
let mca = store
.insert_merchant_connector_account(merchant_connector_account)
.await
- .to_duplicate_response(errors::ApiErrorResponse::DuplicateMerchantConnectorAccount)?;
+ .to_duplicate_response(
+ errors::ApiErrorResponse::DuplicateMerchantConnectorAccount {
+ connector_label: connector_label.clone(),
+ },
+ )?;
let mca_response = ForeignTryFrom::foreign_try_from(mca)?;
diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rs
index 801c812522..729ba18316 100644
--- a/crates/router/src/core/errors/api_error_response.rs
+++ b/crates/router/src/core/errors/api_error_response.rs
@@ -118,8 +118,8 @@ pub enum ApiErrorResponse {
DuplicateMandate,
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The merchant account with the specified details already exists in our records")]
DuplicateMerchantAccount,
- #[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The merchant connector account with the specified details already exists in our records")]
- DuplicateMerchantConnectorAccount,
+ #[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The merchant connector account with the specified connector_label '{connector_label}' already exists in our records")]
+ DuplicateMerchantConnectorAccount { connector_label: String },
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The payment method with the specified details already exists in our records")]
DuplicatePaymentMethod,
#[error(error_type = ErrorType::DuplicateRequest, code = "HE_01", message = "The payment with the specified payment_id '{payment_id}' already exists in our records")]
@@ -270,7 +270,7 @@ impl actix_web::ResponseError for ApiErrorResponse {
| Self::ApiKeyNotFound
| Self::DisputeStatusValidationFailed { .. } => StatusCode::BAD_REQUEST, // 400
Self::DuplicateMerchantAccount
- | Self::DuplicateMerchantConnectorAccount
+ | Self::DuplicateMerchantConnectorAccount { .. }
| Self::DuplicatePaymentMethod
| Self::DuplicateMandate
| Self::DisputeNotFound { .. }
@@ -409,8 +409,8 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
Self::DuplicateRefundRequest => AER::BadRequest(ApiError::new("HE", 1, "Duplicate refund request. Refund already attempted with the refund ID", None)),
Self::DuplicateMandate => AER::BadRequest(ApiError::new("HE", 1, "Duplicate mandate request. Mandate already attempted with the Mandate ID", None)),
Self::DuplicateMerchantAccount => AER::BadRequest(ApiError::new("HE", 1, "The merchant account with the specified details already exists in our records", None)),
- Self::DuplicateMerchantConnectorAccount => {
- AER::BadRequest(ApiError::new("HE", 1, "The merchant connector account with the specified details already exists in our records", None))
+ Self::DuplicateMerchantConnectorAccount { connector_label } => {
+ AER::BadRequest(ApiError::new("HE", 1, format!("The merchant connector account with the specified connector_label '{connector_label}' already exists in our records"), None))
}
Self::DuplicatePaymentMethod => AER::BadRequest(ApiError::new("HE", 1, "The payment method with the specified details already exists in our records", None)),
Self::DuplicatePayment { payment_id } => {