fix(router/webhooks): map webhook event type not found errors to 422 (#1340)

Co-authored-by: Sampras Lopes <lsampras@protonmail.com>
This commit is contained in:
ItsMeShashank
2023-06-02 16:43:47 +05:30
committed by GitHub
parent 166688a590
commit 61bacd8c95
4 changed files with 17 additions and 7 deletions

View File

@ -507,7 +507,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
errors::ApiErrorResponse::WebhookBadRequest
| errors::ApiErrorResponse::WebhookResourceNotFound
| errors::ApiErrorResponse::WebhookProcessingFailure
| errors::ApiErrorResponse::WebhookAuthenticationFailed => Self::WebhookProcessingError,
| errors::ApiErrorResponse::WebhookAuthenticationFailed
| errors::ApiErrorResponse::WebhookUnprocessableEntity => Self::WebhookProcessingError,
}
}
}

View File

@ -194,6 +194,8 @@ pub enum ApiErrorResponse {
WebhookBadRequest,
#[error(error_type = ErrorType::RouterError, code = "WE_03", message = "There was some issue processing the webhook")]
WebhookProcessingFailure,
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_05", message = "Unable to process the webhook body")]
WebhookUnprocessableEntity,
}
#[derive(Clone)]
@ -304,6 +306,7 @@ impl actix_web::ResponseError for ApiErrorResponse {
Self::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE, // 503
Self::PaymentNotSucceeded => StatusCode::BAD_REQUEST, // 400
Self::NotImplemented { .. } => StatusCode::NOT_IMPLEMENTED, // 501
Self::WebhookUnprocessableEntity => StatusCode::UNPROCESSABLE_ENTITY,
}
}
@ -538,6 +541,9 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
Self::WebhookProcessingFailure => {
AER::InternalServerError(ApiError::new("WE", 3, "There was an issue processing the webhook", None))
}
Self::WebhookUnprocessableEntity => {
AER::Unprocessable(ApiError::new("WE", 5, "There was an issue processing the webhook body", None))
}
}
}
}

View File

@ -64,13 +64,16 @@ impl<T> WebhookApiErrorSwitch<T> for errors::CustomResult<T, errors::ConnectorEr
errors::ConnectorError::WebhookSignatureNotFound
| errors::ConnectorError::WebhookReferenceIdNotFound
| errors::ConnectorError::WebhookEventTypeNotFound
| errors::ConnectorError::WebhookResourceObjectNotFound
| errors::ConnectorError::WebhookBodyDecodingFailed
| errors::ConnectorError::WebhooksNotImplemented => {
Err(e).change_context(errors::ApiErrorResponse::WebhookBadRequest)
}
errors::ConnectorError::WebhookEventTypeNotFound => {
Err(e).change_context(errors::ApiErrorResponse::WebhookUnprocessableEntity)
}
_ => Err(e).change_context(errors::ApiErrorResponse::InternalServerError),
},
}