diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs index 2d10e37c10..03b59c5503 100644 --- a/crates/router/src/compatibility/stripe/errors.rs +++ b/crates/router/src/compatibility/stripe/errors.rs @@ -239,6 +239,8 @@ pub enum StripeErrorCode { PaymentLinkNotFound, #[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "Resource Busy. Please try again later")] LockTimeout, + #[error(error_type = StripeErrorType::InvalidRequestError, code = "", message = "Merchant connector account is configured with invalid {config}")] + InvalidConnectorConfiguration { config: String }, // [#216]: https://github.com/juspay/hyperswitch/issues/216 // Implement the remaining stripe error codes @@ -590,6 +592,9 @@ impl From for StripeErrorCode { Self::PaymentMethodUnactivated } errors::ApiErrorResponse::ResourceBusy => Self::PaymentMethodUnactivated, + errors::ApiErrorResponse::InvalidConnectorConfiguration { config } => { + Self::InvalidConnectorConfiguration { config } + } } } } @@ -656,7 +661,8 @@ impl actix_web::ResponseError for StripeErrorCode { | Self::FileProviderNotSupported | Self::CurrencyNotSupported { .. } | Self::DuplicateCustomer - | Self::PaymentMethodUnactivated => StatusCode::BAD_REQUEST, + | Self::PaymentMethodUnactivated + | Self::InvalidConnectorConfiguration { .. } => StatusCode::BAD_REQUEST, Self::RefundFailed | Self::PayoutFailed | Self::PaymentLinkNotFound diff --git a/crates/router/src/connector/braintree/braintree_graphql_transformers.rs b/crates/router/src/connector/braintree/braintree_graphql_transformers.rs index e967caaba8..b622e04191 100644 --- a/crates/router/src/connector/braintree/braintree_graphql_transformers.rs +++ b/crates/router/src/connector/braintree/braintree_graphql_transformers.rs @@ -86,8 +86,8 @@ impl TryFrom<&Option> for BraintreeMeta { type Error = error_stack::Report; fn try_from(meta_data: &Option) -> Result { let metadata: Self = utils::to_connector_meta_from_secret::(meta_data.clone()) - .change_context(errors::ConnectorError::InvalidConfig { - field_name: "merchant connector account metadata", + .change_context(errors::ConnectorError::InvalidConnectorConfig { + config: "metadata", })?; Ok(metadata) } @@ -109,8 +109,8 @@ impl TryFrom<&BraintreeRouterData<&types::PaymentsAuthorizeRouterData>> ) -> Result { let metadata: BraintreeMeta = utils::to_connector_meta_from_secret(item.router_data.connector_meta_data.clone()) - .change_context(errors::ConnectorError::InvalidConfig { - field_name: "merchant connector account metadata", + .change_context(errors::ConnectorError::InvalidConnectorConfig { + config: "metadata", })?; utils::validate_currency( item.router_data.request.currency, @@ -602,8 +602,8 @@ impl TryFrom>> for Braintree ) -> Result { let metadata: BraintreeMeta = utils::to_connector_meta_from_secret(item.router_data.connector_meta_data.clone()) - .change_context(errors::ConnectorError::InvalidConfig { - field_name: "merchant connector account metadata", + .change_context(errors::ConnectorError::InvalidConnectorConfig { + config: "metadata", })?; utils::validate_currency( @@ -712,9 +712,7 @@ impl TryFrom<&types::RefundSyncRouterData> for BraintreeRSyncRequest { let metadata: BraintreeMeta = utils::to_connector_meta_from_secret( item.connector_meta_data.clone(), ) - .change_context(errors::ConnectorError::InvalidConfig { - field_name: "merchant connector account metadata", - })?; + .change_context(errors::ConnectorError::InvalidConnectorConfig { config: "metadata" })?; utils::validate_currency( item.request.currency, Some(metadata.merchant_config_currency), @@ -1345,8 +1343,8 @@ impl TryFrom<&BraintreeRouterData<&types::PaymentsCompleteAuthorizeRouterData>> ) -> Result { let metadata: BraintreeMeta = utils::to_connector_meta_from_secret(item.router_data.connector_meta_data.clone()) - .change_context(errors::ConnectorError::InvalidConfig { - field_name: "merchant connector account metadata", + .change_context(errors::ConnectorError::InvalidConnectorConfig { + config: "metadata", })?; utils::validate_currency( item.router_data.request.currency, diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 46aae8faea..e6c318285b 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -701,11 +701,10 @@ pub async fn create_payment_connector( message: "The connector name is invalid".to_string(), }) } - errors::ConnectorError::InvalidConfig { field_name } => { - err.change_context(errors::ApiErrorResponse::InvalidRequestData { + errors::ConnectorError::InvalidConnectorConfig { config: field_name } => err + .change_context(errors::ApiErrorResponse::InvalidRequestData { message: format!("The {} is invalid", field_name), - }) - } + }), errors::ConnectorError::FailedToObtainAuthType => { err.change_context(errors::ApiErrorResponse::InvalidRequestData { message: "The auth type is invalid for the connector".to_string(), diff --git a/crates/router/src/core/errors.rs b/crates/router/src/core/errors.rs index 9d75904ef6..1c062b7035 100644 --- a/crates/router/src/core/errors.rs +++ b/crates/router/src/core/errors.rs @@ -179,7 +179,7 @@ pub enum ConnectorError { connector: &'static str, }, #[error("Invalid Configuration")] - InvalidConfig { field_name: &'static str }, + InvalidConnectorConfig { config: &'static str }, } #[derive(Debug, thiserror::Error)] diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rs index e606771b37..d34cbf88aa 100644 --- a/crates/router/src/core/errors/api_error_response.rs +++ b/crates/router/src/core/errors/api_error_response.rs @@ -236,6 +236,8 @@ pub enum ApiErrorResponse { WebhookInvalidMerchantSecret, #[error(error_type = ErrorType::InvalidRequestError, code = "IR_19", message = "{message}")] CurrencyNotSupported { message: String }, + #[error(error_type = ErrorType::InvalidRequestError, code = "IR_24", message = "Merchant connector account is configured with invalid {config}")] + InvalidConnectorConfiguration { config: String }, } impl PTError for ApiErrorResponse { diff --git a/crates/router/src/core/errors/transformers.rs b/crates/router/src/core/errors/transformers.rs index 19640a931e..17aa6f3a20 100644 --- a/crates/router/src/core/errors/transformers.rs +++ b/crates/router/src/core/errors/transformers.rs @@ -267,6 +267,9 @@ impl ErrorSwitch for ApiErrorRespon Self::PaymentLinkNotFound => { AER::NotFound(ApiError::new("HE", 2, "Payment Link does not exist in our records", None)) } + Self::InvalidConnectorConfiguration {config} => { + AER::BadRequest(ApiError::new("IR", 24, format!("Merchant connector account is configured with invalid {config}"), None)) + } } } } diff --git a/crates/router/src/core/errors/utils.rs b/crates/router/src/core/errors/utils.rs index 8a86be2036..c3cdf95b87 100644 --- a/crates/router/src/core/errors/utils.rs +++ b/crates/router/src/core/errors/utils.rs @@ -205,7 +205,48 @@ impl ConnectorErrorExt for error_stack::Result errors::ApiErrorResponse::InvalidDataValue { field_name } }, errors::ConnectorError::CurrencyNotSupported { message, connector} => errors::ApiErrorResponse::CurrencyNotSupported { message: format!("Credentials for the currency {message} are not configured with the connector {connector}/hyperswitch") }, - _ => errors::ApiErrorResponse::InternalServerError, + errors::ConnectorError::FailedToObtainAuthType => errors::ApiErrorResponse::InvalidConnectorConfiguration {config: "connector_account_details".to_string()}, + errors::ConnectorError::InvalidConnectorConfig { config } => errors::ApiErrorResponse::InvalidConnectorConfiguration { config: config.to_string() }, + errors::ConnectorError::FailedToObtainIntegrationUrl | + errors::ConnectorError::RequestEncodingFailed | + errors::ConnectorError::RequestEncodingFailedWithReason(_) | + errors::ConnectorError::ParsingFailed | + errors::ConnectorError::ResponseDeserializationFailed | + errors::ConnectorError::UnexpectedResponseError(_) | + errors::ConnectorError::RoutingRulesParsingError | + errors::ConnectorError::FailedToObtainPreferredConnector | + errors::ConnectorError::InvalidConnectorName | + errors::ConnectorError::InvalidWallet | + errors::ConnectorError::ResponseHandlingFailed | + errors::ConnectorError::FailedToObtainCertificate | + errors::ConnectorError::NoConnectorMetaData | + errors::ConnectorError::FailedToObtainCertificateKey | + errors::ConnectorError::CaptureMethodNotSupported | + errors::ConnectorError::MissingConnectorMandateID | + errors::ConnectorError::MissingConnectorTransactionID | + errors::ConnectorError::MissingConnectorRefundID | + errors::ConnectorError::MissingApplePayTokenData | + errors::ConnectorError::WebhooksNotImplemented | + errors::ConnectorError::WebhookBodyDecodingFailed | + errors::ConnectorError::WebhookSignatureNotFound | + errors::ConnectorError::WebhookSourceVerificationFailed | + errors::ConnectorError::WebhookVerificationSecretNotFound | + errors::ConnectorError::WebhookVerificationSecretInvalid | + errors::ConnectorError::WebhookReferenceIdNotFound | + errors::ConnectorError::WebhookEventTypeNotFound | + errors::ConnectorError::WebhookResourceObjectNotFound | + errors::ConnectorError::WebhookResponseEncodingFailed | + errors::ConnectorError::InvalidDateFormat | + errors::ConnectorError::DateFormattingFailed | + errors::ConnectorError::InvalidWalletToken | + errors::ConnectorError::MissingConnectorRelatedTransactionID { .. } | + errors::ConnectorError::FileValidationFailed { .. } | + errors::ConnectorError::MissingConnectorRedirectionPayload { .. } | + errors::ConnectorError::FailedAtConnector { .. } | + errors::ConnectorError::MissingPaymentMethodType | + errors::ConnectorError::InSufficientBalanceInPaymentMethod | + errors::ConnectorError::RequestTimeoutReceived | + errors::ConnectorError::ProcessingStepFailed(None) => errors::ApiErrorResponse::InternalServerError }; err.change_context(error) }) @@ -235,8 +276,64 @@ impl ConnectorErrorExt for error_stack::Result errors::ConnectorError::MissingRequiredField { field_name } => { errors::ApiErrorResponse::MissingRequiredField { field_name } } - _ => { - logger::error!(%error,"Verify flow failed"); + errors::ConnectorError::FailedToObtainIntegrationUrl => { + errors::ApiErrorResponse::InvalidConnectorConfiguration { + config: "connector_account_details".to_string(), + } + } + errors::ConnectorError::InvalidConnectorConfig { config: field_name } => { + errors::ApiErrorResponse::InvalidConnectorConfiguration { + config: field_name.to_string(), + } + } + errors::ConnectorError::RequestEncodingFailed + | errors::ConnectorError::RequestEncodingFailedWithReason(_) + | errors::ConnectorError::ParsingFailed + | errors::ConnectorError::ResponseDeserializationFailed + | errors::ConnectorError::UnexpectedResponseError(_) + | errors::ConnectorError::RoutingRulesParsingError + | errors::ConnectorError::FailedToObtainPreferredConnector + | errors::ConnectorError::InvalidConnectorName + | errors::ConnectorError::InvalidWallet + | errors::ConnectorError::ResponseHandlingFailed + | errors::ConnectorError::MissingRequiredFields { .. } + | errors::ConnectorError::FailedToObtainAuthType + | errors::ConnectorError::FailedToObtainCertificate + | errors::ConnectorError::NoConnectorMetaData + | errors::ConnectorError::FailedToObtainCertificateKey + | errors::ConnectorError::NotImplemented(_) + | errors::ConnectorError::NotSupported { .. } + | errors::ConnectorError::FlowNotSupported { .. } + | errors::ConnectorError::CaptureMethodNotSupported + | errors::ConnectorError::MissingConnectorMandateID + | errors::ConnectorError::MissingConnectorTransactionID + | errors::ConnectorError::MissingConnectorRefundID + | errors::ConnectorError::MissingApplePayTokenData + | errors::ConnectorError::WebhooksNotImplemented + | errors::ConnectorError::WebhookBodyDecodingFailed + | errors::ConnectorError::WebhookSignatureNotFound + | errors::ConnectorError::WebhookSourceVerificationFailed + | errors::ConnectorError::WebhookVerificationSecretNotFound + | errors::ConnectorError::WebhookVerificationSecretInvalid + | errors::ConnectorError::WebhookReferenceIdNotFound + | errors::ConnectorError::WebhookEventTypeNotFound + | errors::ConnectorError::WebhookResourceObjectNotFound + | errors::ConnectorError::WebhookResponseEncodingFailed + | errors::ConnectorError::InvalidDateFormat + | errors::ConnectorError::DateFormattingFailed + | errors::ConnectorError::InvalidDataFormat { .. } + | errors::ConnectorError::MismatchedPaymentData + | errors::ConnectorError::InvalidWalletToken + | errors::ConnectorError::MissingConnectorRelatedTransactionID { .. } + | errors::ConnectorError::FileValidationFailed { .. } + | errors::ConnectorError::MissingConnectorRedirectionPayload { .. } + | errors::ConnectorError::FailedAtConnector { .. } + | errors::ConnectorError::MissingPaymentMethodType + | errors::ConnectorError::InSufficientBalanceInPaymentMethod + | errors::ConnectorError::RequestTimeoutReceived + | errors::ConnectorError::CurrencyNotSupported { .. } + | errors::ConnectorError::ProcessingStepFailed(None) => { + logger::error!(%error,"Setup Mandate flow failed"); errors::ApiErrorResponse::PaymentAuthorizationFailed { data: None } } };