mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 17:47:54 +08:00
refactor(errors): refactor actix_web::ResponseError for ApiErrorResponse (#1362)
This commit is contained in:
committed by
GitHub
parent
5d515050cf
commit
02a3ce74b8
@ -236,95 +236,17 @@ impl ::core::fmt::Display for ApiErrorResponse {
|
||||
|
||||
impl actix_web::ResponseError for ApiErrorResponse {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
Self::Unauthorized
|
||||
| Self::InvalidEphemeralKey
|
||||
| Self::InvalidJwtToken
|
||||
| Self::GenericUnauthorized { .. }
|
||||
| Self::WebhookAuthenticationFailed => StatusCode::UNAUTHORIZED, // 401
|
||||
Self::ExternalConnectorError { status_code, .. } => {
|
||||
StatusCode::from_u16(*status_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
}
|
||||
Self::AccessForbidden => StatusCode::FORBIDDEN, // 403
|
||||
Self::InvalidRequestUrl | Self::WebhookResourceNotFound => StatusCode::NOT_FOUND, // 404
|
||||
Self::InvalidHttpMethod => StatusCode::METHOD_NOT_ALLOWED, // 405
|
||||
Self::MissingRequiredField { .. }
|
||||
| Self::MissingRequiredFields { .. }
|
||||
| Self::InvalidDataValue { .. }
|
||||
| Self::InvalidCardIin
|
||||
| Self::InvalidCardIinLength => StatusCode::BAD_REQUEST, // 400
|
||||
Self::InvalidDataFormat { .. } | Self::InvalidRequestData { .. } => {
|
||||
StatusCode::UNPROCESSABLE_ENTITY
|
||||
} // 422
|
||||
|
||||
Self::PaymentAuthorizationFailed { .. }
|
||||
| Self::PaymentAuthenticationFailed { .. }
|
||||
| Self::PaymentCaptureFailed { .. }
|
||||
| Self::InvalidCardData { .. }
|
||||
| Self::CardExpired { .. }
|
||||
| Self::RefundFailed { .. }
|
||||
| Self::RefundNotPossible { .. }
|
||||
| Self::VerificationFailed { .. }
|
||||
| Self::PaymentUnexpectedState { .. }
|
||||
| Self::MandateValidationFailed { .. }
|
||||
| Self::DisputeFailed { .. }
|
||||
| Self::RefundAmountExceedsPaymentAmount
|
||||
| Self::MaximumRefundCount
|
||||
| Self::IncorrectPaymentMethodConfiguration
|
||||
| Self::PreconditionFailed { .. } => StatusCode::BAD_REQUEST, // 400
|
||||
|
||||
Self::MandateUpdateFailed
|
||||
| Self::InternalServerError
|
||||
| Self::WebhookProcessingFailure => StatusCode::INTERNAL_SERVER_ERROR, // 500
|
||||
Self::DuplicateRefundRequest | Self::DuplicatePayment { .. } => StatusCode::BAD_REQUEST, // 400
|
||||
Self::RefundNotFound
|
||||
| Self::CustomerNotFound
|
||||
| Self::MandateActive
|
||||
| Self::CustomerRedacted
|
||||
| Self::PaymentNotFound
|
||||
| Self::PaymentMethodNotFound
|
||||
| Self::MerchantAccountNotFound
|
||||
| Self::MerchantConnectorAccountNotFound { .. }
|
||||
| Self::MerchantConnectorAccountDisabled
|
||||
| Self::MandateNotFound
|
||||
| Self::ClientSecretNotGiven
|
||||
| Self::ClientSecretExpired
|
||||
| Self::ClientSecretInvalid
|
||||
| Self::SuccessfulPaymentNotFound
|
||||
| Self::IncorrectConnectorNameGiven
|
||||
| Self::ResourceIdNotFound
|
||||
| Self::ConfigNotFound
|
||||
| Self::AddressNotFound
|
||||
| Self::NotSupported { .. }
|
||||
| Self::FlowNotSupported { .. }
|
||||
| Self::ApiKeyNotFound
|
||||
| Self::DisputeStatusValidationFailed { .. }
|
||||
| Self::WebhookBadRequest => StatusCode::BAD_REQUEST, // 400
|
||||
Self::DuplicateMerchantAccount
|
||||
| Self::DuplicateMerchantConnectorAccount { .. }
|
||||
| Self::DuplicatePaymentMethod
|
||||
| Self::DuplicateMandate
|
||||
| Self::DisputeNotFound { .. }
|
||||
| Self::MissingFile
|
||||
| Self::FileValidationFailed { .. }
|
||||
| Self::MissingFileContentType
|
||||
| Self::MissingFilePurpose
|
||||
| Self::MissingDisputeId
|
||||
| Self::FileNotFound
|
||||
| Self::FileNotAvailable => StatusCode::BAD_REQUEST, // 400
|
||||
Self::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE, // 503
|
||||
Self::PaymentNotSucceeded => StatusCode::BAD_REQUEST, // 400
|
||||
Self::NotImplemented { .. } => StatusCode::NOT_IMPLEMENTED, // 501
|
||||
Self::WebhookUnprocessableEntity => StatusCode::UNPROCESSABLE_ENTITY,
|
||||
}
|
||||
common_utils::errors::ErrorSwitch::<api_models::errors::types::ApiErrorResponse>::switch(
|
||||
self,
|
||||
)
|
||||
.status_code()
|
||||
}
|
||||
|
||||
fn error_response(&self) -> actix_web::HttpResponse {
|
||||
use actix_web::http::header;
|
||||
|
||||
actix_web::HttpResponseBuilder::new(self.status_code())
|
||||
.insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON))
|
||||
.body(self.to_string())
|
||||
common_utils::errors::ErrorSwitch::<api_models::errors::types::ApiErrorResponse>::switch(
|
||||
self,
|
||||
)
|
||||
.error_response()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user