chore(router): added generic unauthorized response (#450)

This commit is contained in:
Rachit Naithani
2023-01-22 18:07:19 +05:30
committed by GitHub
parent a447921c15
commit 2c764a273e
2 changed files with 10 additions and 3 deletions

View File

@ -321,6 +321,7 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
match value { match value {
errors::ApiErrorResponse::Unauthorized errors::ApiErrorResponse::Unauthorized
| errors::ApiErrorResponse::InvalidJwtToken | errors::ApiErrorResponse::InvalidJwtToken
| errors::ApiErrorResponse::GenericUnauthorized { .. }
| errors::ApiErrorResponse::InvalidEphermeralKey => Self::Unauthorized, | errors::ApiErrorResponse::InvalidEphermeralKey => Self::Unauthorized,
errors::ApiErrorResponse::InvalidRequestUrl errors::ApiErrorResponse::InvalidRequestUrl
| errors::ApiErrorResponse::InvalidHttpMethod => Self::InvalidRequestUrl, | errors::ApiErrorResponse::InvalidHttpMethod => Self::InvalidRequestUrl,

View File

@ -73,6 +73,11 @@ pub enum ApiErrorResponse {
message = "Access forbidden, invalid JWT token was used." message = "Access forbidden, invalid JWT token was used."
)] )]
InvalidJwtToken, InvalidJwtToken,
#[error(
error_type = ErrorType::InvalidRequestError, code = "IR_12",
message = "{message}",
)]
GenericUnauthorized { message: String },
#[error(error_type = ErrorType::ProcessingError, code = "CE_01", message = "Payment failed while processing with connector. Retry payment.")] #[error(error_type = ErrorType::ProcessingError, code = "CE_01", message = "Payment failed while processing with connector. Retry payment.")]
PaymentAuthorizationFailed { data: Option<serde_json::Value> }, PaymentAuthorizationFailed { data: Option<serde_json::Value> },
@ -179,9 +184,10 @@ impl actix_web::ResponseError for ApiErrorResponse {
use reqwest::StatusCode; use reqwest::StatusCode;
match self { match self {
Self::Unauthorized | Self::InvalidEphermeralKey | Self::InvalidJwtToken => { Self::Unauthorized
StatusCode::UNAUTHORIZED | Self::InvalidEphermeralKey
} // 401 | Self::InvalidJwtToken
| Self::GenericUnauthorized { .. } => StatusCode::UNAUTHORIZED, // 401
Self::ExternalConnectorError { status_code, .. } => { Self::ExternalConnectorError { status_code, .. } => {
StatusCode::from_u16(*status_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR) StatusCode::from_u16(*status_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR)
} }