Skip to content

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

fix(error): propagate MissingRequiredFields api_error (#1244)

Chethan Rao798881ab5b0e
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs
index 4445ec4ce4..45338b6b7d 100644
--- a/crates/router/src/compatibility/stripe/errors.rs
+++ b/crates/router/src/compatibility/stripe/errors.rs
@@ -20,10 +20,7 @@ pub enum StripeErrorCode {
InvalidRequestUrl,
#[error(error_type = StripeErrorType::InvalidRequestError, code = "parameter_missing", message = "Missing required param: {field_name}.")]
- ParameterMissing {
- field_name: &'static str,
- param: &'static str,
- },
+ ParameterMissing { field_name: String, param: String },
#[error(
error_type = StripeErrorType::InvalidRequestError, code = "parameter_unknown",
@@ -373,8 +370,15 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
| errors::ApiErrorResponse::InvalidCardIinLength => Self::InvalidRequestUrl,
errors::ApiErrorResponse::MissingRequiredField { field_name } => {
Self::ParameterMissing {
- field_name,
- param: field_name,
+ field_name: field_name.to_string(),
+ param: field_name.to_string(),
+ }
+ }
+ errors::ApiErrorResponse::MissingRequiredFields { field_names } => {
+ // Instead of creating a new error variant in StripeErrorCode for MissingRequiredFields, converted vec<&str> to String
+ Self::ParameterMissing {
+ field_name: field_names.clone().join(", "),
+ param: field_names.clone().join(", "),
}
}
// parameter unknown, invalid request error // actually if we type wrong values in address we get this error. Stripe throws parameter unknown. I don't know if stripe is validating email and stuff
@@ -458,8 +462,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
Self::PreconditionFailed { message }
}
errors::ApiErrorResponse::InvalidDataValue { field_name } => Self::ParameterMissing {
- field_name,
- param: field_name,
+ field_name: field_name.to_string(),
+ param: field_name.to_string(),
},
errors::ApiErrorResponse::MaximumRefundCount => Self::MaximumRefundCount,
errors::ApiErrorResponse::PaymentNotSucceeded => Self::PaymentFailed,
diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rs
index 20b585fb0a..64addea4b8 100644
--- a/crates/router/src/core/errors/api_error_response.rs
+++ b/crates/router/src/core/errors/api_error_response.rs
@@ -87,6 +87,8 @@ pub enum ApiErrorResponse {
NotSupported { message: String },
#[error(error_type = ErrorType::InvalidRequestError, code = "IR_20", message = "{flow} flow not supported by the {connector} connector")]
FlowNotSupported { flow: String, connector: String },
+ #[error(error_type = ErrorType::InvalidRequestError, code = "IR_21", message = "Missing required params")]
+ MissingRequiredFields { field_names: Vec<&'static str> },
#[error(error_type = ErrorType::ConnectorError, code = "CE_00", message = "{code}: {message}", ignore = "status_code")]
ExternalConnectorError {
code: String,
@@ -238,6 +240,7 @@ impl actix_web::ResponseError for ApiErrorResponse {
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
@@ -400,6 +403,9 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
19,
"The provided client_secret has expired", None
)),
+ Self::MissingRequiredFields { field_names } => AER::BadRequest(
+ ApiError::new("IR", 21, "Missing required params".to_string(), Some(Extra {data: Some(serde_json::json!(field_names)), ..Default::default() })),
+ ),
Self::ExternalConnectorError {
code,
message,
diff --git a/crates/router/src/core/errors/utils.rs b/crates/router/src/core/errors/utils.rs
index b4c7f10ccf..25fa8a5664 100644
--- a/crates/router/src/core/errors/utils.rs
+++ b/crates/router/src/core/errors/utils.rs
@@ -94,6 +94,9 @@ impl ConnectorErrorExt for error_stack::Report<errors::ConnectorError> {
errors::ConnectorError::MissingRequiredField { field_name } => {
errors::ApiErrorResponse::MissingRequiredField { field_name }
}
+ errors::ConnectorError::MissingRequiredFields { field_names } => {
+ errors::ApiErrorResponse::MissingRequiredFields { field_names: field_names.to_vec() }
+ }
errors::ConnectorError::NotImplemented(reason) => {
errors::ApiErrorResponse::NotImplemented {
message: errors::api_error_response::NotImplementedMessage::Reason(