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
refactor(router): fixed unprocessable entity error message to custom message (#1979)
Sahkal Poddar655b388358ec
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rsindex 9be092a672..8c3c62b01f 100644--- a/crates/router/src/compatibility/stripe/errors.rs+++ b/crates/router/src/compatibility/stripe/errors.rs@@ -223,8 +223,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 },+ #[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "{message}")]+ HyperswitchUnprocessableEntity { message: String },#[error(error_type = StripeErrorType::InvalidRequestError, code = "", message = "{message}")]CurrencyNotSupported { message: String },// [#216]: https://github.com/juspay/hyperswitch/issues/216@@ -403,8 +403,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {param: field_name.to_string(),}}- errors::ApiErrorResponse::UnprocessableEntity { entity } => {- Self::HyperswitchUnprocessableEntity { entity }+ errors::ApiErrorResponse::UnprocessableEntity { message } => {+ Self::HyperswitchUnprocessableEntity { message }}errors::ApiErrorResponse::MissingRequiredFields { field_names } => {// Instead of creating a new error variant in StripeErrorCode for MissingRequiredFields, converted vec<&str> to Stringdiff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rsindex 6546c26e61..de07f061c8 100644--- a/crates/router/src/core/errors/api_error_response.rs+++ b/crates/router/src/core/errors/api_error_response.rs@@ -92,8 +92,8 @@ pub enum ApiErrorResponse {AccessForbidden,#[error(error_type = ErrorType::InvalidRequestError, code = "IR_23", message = "{message}")]FileProviderNotSupported { message: String },- #[error(error_type = ErrorType::InvalidRequestError, code = "IR_23", message = "{entity} expired or invalid")]- UnprocessableEntity { entity: String },+ #[error(error_type = ErrorType::InvalidRequestError, code = "IR_23", message = "{message}")]+ UnprocessableEntity { message: String },#[error(error_type = ErrorType::ConnectorError, code = "CE_00", message = "{code}: {message}", ignore = "status_code")]ExternalConnectorError {code: String,diff --git a/crates/router/src/core/errors/transformers.rs b/crates/router/src/core/errors/transformers.rsindex a139261da9..208aad56ee 100644--- a/crates/router/src/core/errors/transformers.rs+++ b/crates/router/src/core/errors/transformers.rs@@ -93,7 +93,7 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorResponSelf::FileProviderNotSupported { message } => {AER::BadRequest(ApiError::new("IR", 23, message.to_string(), None))},- Self::UnprocessableEntity {entity} => AER::Unprocessable(ApiError::new("IR", 23, format!("{entity} expired or invalid"), None)),+ Self::UnprocessableEntity {message} => AER::Unprocessable(ApiError::new("IR", 23, message.to_string(), 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 0a647d6a54..3f593fcea9 100644--- a/crates/router/src/core/payment_methods/vault.rs+++ b/crates/router/src/core/payment_methods/vault.rs@@ -1085,7 +1085,7 @@ pub async fn get_tokenized_data(metrics::TEMP_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);match err.status_code {404 => Err(errors::ApiErrorResponse::UnprocessableEntity {- entity: "Token".to_string(),+ message: "Token is invalid or expired".into(),}.into()),_ => Err(errors::ApiErrorResponse::InternalServerError)diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex d63551bdbf..5fe34c3385 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -1202,7 +1202,9 @@ pub async fn make_pm_data<'a, F: Clone, R>(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to fetch the token from redis")?.ok_or(error_stack::Report::new(- errors::ApiErrorResponse::UnprocessableEntity { entity: token },+ errors::ApiErrorResponse::UnprocessableEntity {+ message: token + " is invalid or expired",+ },))?;Some(key)@@ -2424,7 +2426,7 @@ pub async fn get_merchant_connector_account(let decrypted_mca = services::decrypt_jwe(mca_config.config.as_str(), services::KeyIdCheck::SkipKeyIdCheck, private_key, jwe::RSA_OAEP_256).await.change_context(errors::ApiErrorResponse::UnprocessableEntity{- entity: "merchant_connector_details".to_string()})+ message: "decoding merchant_connector_details failed due to invalid data format!".into()}).attach_printable("Failed to decrypt merchant_connector_details sent in request and then put in cache",)?;