mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
fix(payment_methods): return appropriate error when basilisk locker token expires (#1517)
Co-authored-by: SamraatBansal <samraatbansal7@gmail.com>
This commit is contained in:
@ -203,6 +203,8 @@ pub enum StripeErrorCode {
|
|||||||
WebhookProcessingError,
|
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.")]
|
#[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,
|
PaymentMethodUnactivated,
|
||||||
|
#[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "{entity} expired or invalid")]
|
||||||
|
HyperswitchUnprocessableEntity { entity: String },
|
||||||
// [#216]: https://github.com/juspay/hyperswitch/issues/216
|
// [#216]: https://github.com/juspay/hyperswitch/issues/216
|
||||||
// Implement the remaining stripe error codes
|
// Implement the remaining stripe error codes
|
||||||
|
|
||||||
@ -379,6 +381,9 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
|
|||||||
param: field_name.to_string(),
|
param: field_name.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
errors::ApiErrorResponse::UnprocessableEntity { entity } => {
|
||||||
|
Self::HyperswitchUnprocessableEntity { entity }
|
||||||
|
}
|
||||||
errors::ApiErrorResponse::MissingRequiredFields { field_names } => {
|
errors::ApiErrorResponse::MissingRequiredFields { field_names } => {
|
||||||
// Instead of creating a new error variant in StripeErrorCode for MissingRequiredFields, converted vec<&str> to String
|
// Instead of creating a new error variant in StripeErrorCode for MissingRequiredFields, converted vec<&str> to String
|
||||||
Self::ParameterMissing {
|
Self::ParameterMissing {
|
||||||
@ -529,7 +534,9 @@ impl actix_web::ResponseError for StripeErrorCode {
|
|||||||
match self {
|
match self {
|
||||||
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
||||||
Self::InvalidRequestUrl => StatusCode::NOT_FOUND,
|
Self::InvalidRequestUrl => StatusCode::NOT_FOUND,
|
||||||
Self::ParameterUnknown { .. } => StatusCode::UNPROCESSABLE_ENTITY,
|
Self::ParameterUnknown { .. } | Self::HyperswitchUnprocessableEntity { .. } => {
|
||||||
|
StatusCode::UNPROCESSABLE_ENTITY
|
||||||
|
}
|
||||||
Self::ParameterMissing { .. }
|
Self::ParameterMissing { .. }
|
||||||
| Self::RefundAmountExceedsPaymentAmount { .. }
|
| Self::RefundAmountExceedsPaymentAmount { .. }
|
||||||
| Self::PaymentIntentAuthenticationFailure { .. }
|
| Self::PaymentIntentAuthenticationFailure { .. }
|
||||||
|
|||||||
@ -91,6 +91,8 @@ pub enum ApiErrorResponse {
|
|||||||
MissingRequiredFields { field_names: Vec<&'static str> },
|
MissingRequiredFields { field_names: Vec<&'static str> },
|
||||||
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_22", message = "Access forbidden. Not authorized to access this resource")]
|
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_22", message = "Access forbidden. Not authorized to access this resource")]
|
||||||
AccessForbidden,
|
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")]
|
#[error(error_type = ErrorType::ConnectorError, code = "CE_00", message = "{code}: {message}", ignore = "status_code")]
|
||||||
ExternalConnectorError {
|
ExternalConnectorError {
|
||||||
code: String,
|
code: String,
|
||||||
@ -341,6 +343,7 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
|
|||||||
ApiError::new("IR", 21, "Missing required params".to_string(), Some(Extra {data: Some(serde_json::json!(field_names)), ..Default::default() })),
|
ApiError::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::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 {
|
Self::ExternalConnectorError {
|
||||||
code,
|
code,
|
||||||
message,
|
message,
|
||||||
|
|||||||
@ -630,9 +630,15 @@ pub async fn get_tokenized_data(
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
metrics::TEMP_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);
|
metrics::TEMP_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]);
|
||||||
Err(errors::ApiErrorResponse::InternalServerError)
|
match err.status_code {
|
||||||
.into_report()
|
404 => Err(errors::ApiErrorResponse::UnprocessableEntity {
|
||||||
.attach_printable(format!("Got 4xx from the basilisk locker: {err:?}"))
|
entity: "Token".to_string(),
|
||||||
|
}
|
||||||
|
.into()),
|
||||||
|
_ => Err(errors::ApiErrorResponse::InternalServerError)
|
||||||
|
.into_report()
|
||||||
|
.attach_printable(format!("Got error from the basilisk locker: {err:?}")),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user