Skip to content

Commit

Permalink
refactor(router): fixed unprocessable entity error message to custom …
Browse files Browse the repository at this point in the history
…message (#1979)

Co-authored-by: Sahkal Poddar <[email protected]>
  • Loading branch information
sahkal and sahkal authored Aug 31, 2023
1 parent 636b871 commit 655b388
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions crates/router/src/compatibility/stripe/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 String
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/core/errors/api_error_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/errors/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
Self::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,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/payment_methods/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
)?;
Expand Down

0 comments on commit 655b388

Please sign in to comment.