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

10
Cargo.lock generated
View File

@ -3058,7 +3058,7 @@ dependencies = [
[[package]]
name = "opentelemetry"
version = "0.18.0"
source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"opentelemetry_api",
"opentelemetry_sdk",
@ -3067,7 +3067,7 @@ dependencies = [
[[package]]
name = "opentelemetry-otlp"
version = "0.11.0"
source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"async-trait",
"futures",
@ -3084,7 +3084,7 @@ dependencies = [
[[package]]
name = "opentelemetry-proto"
version = "0.1.0"
source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"futures",
"futures-util",
@ -3096,7 +3096,7 @@ dependencies = [
[[package]]
name = "opentelemetry_api"
version = "0.18.0"
source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"fnv",
"futures-channel",
@ -3111,7 +3111,7 @@ dependencies = [
[[package]]
name = "opentelemetry_sdk"
version = "0.18.0"
source = "git+https://github.com/open-telemetry/opentelemetry-rust/?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
source = "git+https://github.com/open-telemetry/opentelemetry-rust?rev=44b90202fd744598db8b0ace5b8f0bad7ec45658#44b90202fd744598db8b0ace5b8f0bad7ec45658"
dependencies = [
"async-trait",
"crossbeam-channel",

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),
},
}