feat: add error type for empty connector list (#1363)

Co-authored-by: ItsMeShashank <shashank.attarde@juspay.in>
This commit is contained in:
Narayan Bhat
2023-06-08 12:03:52 +05:30
committed by GitHub
parent b3b16fcf95
commit b2da920280
2 changed files with 17 additions and 6 deletions

View File

@ -198,6 +198,8 @@ pub enum StripeErrorCode {
FileNotAvailable, FileNotAvailable,
#[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "There was an issue with processing webhooks")] #[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "There was an issue with processing webhooks")]
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.")]
PaymentMethodUnactivated,
// [#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
@ -298,7 +300,6 @@ pub enum StripeErrorCode {
PaymentMethodMicrodepositVerificationTimeout, PaymentMethodMicrodepositVerificationTimeout,
PaymentMethodProviderDecline, PaymentMethodProviderDecline,
PaymentMethodProviderTimeout, PaymentMethodProviderTimeout,
PaymentMethodUnactivated,
PaymentMethodUnexpectedState, PaymentMethodUnexpectedState,
PaymentMethodUnsupportedType, PaymentMethodUnsupportedType,
PayoutsNotAllowed, PayoutsNotAllowed,
@ -509,6 +510,9 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
| errors::ApiErrorResponse::WebhookProcessingFailure | errors::ApiErrorResponse::WebhookProcessingFailure
| errors::ApiErrorResponse::WebhookAuthenticationFailed | errors::ApiErrorResponse::WebhookAuthenticationFailed
| errors::ApiErrorResponse::WebhookUnprocessableEntity => Self::WebhookProcessingError, | errors::ApiErrorResponse::WebhookUnprocessableEntity => Self::WebhookProcessingError,
errors::ApiErrorResponse::IncorrectPaymentMethodConfiguration => {
Self::PaymentMethodUnactivated
}
} }
} }
} }
@ -564,7 +568,8 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::MissingFilePurpose | Self::MissingFilePurpose
| Self::MissingDisputeId | Self::MissingDisputeId
| Self::FileNotFound | Self::FileNotFound
| Self::FileNotAvailable => StatusCode::BAD_REQUEST, | Self::FileNotAvailable
| Self::PaymentMethodUnactivated => StatusCode::BAD_REQUEST,
Self::RefundFailed Self::RefundFailed
| Self::InternalServerError | Self::InternalServerError
| Self::MandateActive | Self::MandateActive

View File

@ -194,6 +194,8 @@ pub enum ApiErrorResponse {
WebhookBadRequest, WebhookBadRequest,
#[error(error_type = ErrorType::RouterError, code = "WE_03", message = "There was some issue processing the webhook")] #[error(error_type = ErrorType::RouterError, code = "WE_03", message = "There was some issue processing the webhook")]
WebhookProcessingFailure, WebhookProcessingFailure,
#[error(error_type = ErrorType::InvalidRequestError, code = "HE_04", message = "required payment method is not configured or configured incorrectly for all configured connectors")]
IncorrectPaymentMethodConfiguration,
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_05", message = "Unable to process the webhook body")] #[error(error_type = ErrorType::InvalidRequestError, code = "WE_05", message = "Unable to process the webhook body")]
WebhookUnprocessableEntity, WebhookUnprocessableEntity,
} }
@ -249,9 +251,6 @@ impl actix_web::ResponseError for ApiErrorResponse {
Self::InvalidDataFormat { .. } | Self::InvalidRequestData { .. } => { Self::InvalidDataFormat { .. } | Self::InvalidRequestData { .. } => {
StatusCode::UNPROCESSABLE_ENTITY StatusCode::UNPROCESSABLE_ENTITY
} // 422 } // 422
Self::RefundAmountExceedsPaymentAmount => StatusCode::BAD_REQUEST, // 400
Self::MaximumRefundCount => StatusCode::BAD_REQUEST, // 400
Self::PreconditionFailed { .. } => StatusCode::BAD_REQUEST, // 400
Self::PaymentAuthorizationFailed { .. } Self::PaymentAuthorizationFailed { .. }
| Self::PaymentAuthenticationFailed { .. } | Self::PaymentAuthenticationFailed { .. }
@ -262,7 +261,11 @@ impl actix_web::ResponseError for ApiErrorResponse {
| Self::RefundNotPossible { .. } | Self::RefundNotPossible { .. }
| Self::VerificationFailed { .. } | Self::VerificationFailed { .. }
| Self::PaymentUnexpectedState { .. } | Self::PaymentUnexpectedState { .. }
| Self::MandateValidationFailed { .. } => StatusCode::BAD_REQUEST, // 400 | Self::MandateValidationFailed { .. }
| Self::RefundAmountExceedsPaymentAmount
| Self::MaximumRefundCount
| Self::IncorrectPaymentMethodConfiguration
| Self::PreconditionFailed { .. } => StatusCode::BAD_REQUEST, // 400
Self::MandateUpdateFailed Self::MandateUpdateFailed
| Self::InternalServerError | Self::InternalServerError
@ -540,6 +543,9 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
} }
Self::WebhookProcessingFailure => { Self::WebhookProcessingFailure => {
AER::InternalServerError(ApiError::new("WE", 3, "There was an issue processing the webhook", None)) AER::InternalServerError(ApiError::new("WE", 3, "There was an issue processing the webhook", None))
},
Self::IncorrectPaymentMethodConfiguration => {
AER::BadRequest(ApiError::new("HE", 4, "No eligible connector was found for the current payment method configuration", None))
} }
Self::WebhookUnprocessableEntity => { Self::WebhookUnprocessableEntity => {
AER::Unprocessable(ApiError::new("WE", 5, "There was an issue processing the webhook body", None)) AER::Unprocessable(ApiError::new("WE", 5, "There was an issue processing the webhook body", None))