Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(router/webhooks): map webhook event type not found errors to 422 (#1340)
ItsMeShashank61bacd8c9590
diff --git a/Cargo.lock b/Cargo.lockindex fd55c2dc31..3690b93799 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -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",diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rsindex 45338b6b7d..17b33da056 100644--- a/crates/router/src/compatibility/stripe/errors.rs+++ b/crates/router/src/compatibility/stripe/errors.rs@@ -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,}}}diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rsindex 64addea4b8..6955082a07 100644--- a/crates/router/src/core/errors/api_error_response.rs+++ b/crates/router/src/core/errors/api_error_response.rs@@ -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, // 503Self::PaymentNotSucceeded => StatusCode::BAD_REQUEST, // 400Self::NotImplemented { .. } => StatusCode::NOT_IMPLEMENTED, // 501+ Self::WebhookUnprocessableEntity => StatusCode::UNPROCESSABLE_ENTITY,}}@@ -538,6 +541,9 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorResponSelf::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))+ }}}}diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rsindex 647d06de19..35bca6c30c 100644--- a/crates/router/src/core/webhooks/utils.rs+++ b/crates/router/src/core/webhooks/utils.rs@@ -64,13 +64,16 @@ impl<T> WebhookApiErrorSwitch<T> for errors::CustomResult<T, errors::ConnectorErerrors::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),},}