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(core): Error propagation for not supporting partial refund (#2976)
Sakil Mostak97a38a78e514
diff --git a/crates/router/src/connector/prophetpay/transformers.rs b/crates/router/src/connector/prophetpay/transformers.rsindex a2c3c55c02..d81b931edf 100644--- a/crates/router/src/connector/prophetpay/transformers.rs+++ b/crates/router/src/connector/prophetpay/transformers.rs@@ -583,10 +583,7 @@ impl<F> TryFrom<&ProphetpayRouterData<&types::RefundsRouterData<F>>> for Prophetaction_type: ProphetpayActionType::get_action_type(&ProphetpayActionType::Refund),})} else {- Err(errors::ConnectorError::NotImplemented(- "Partial Refund is Not Supported".to_string(),- )- .into())+ Err(errors::ConnectorError::NotImplemented("Partial Refund".to_string()).into())}}}diff --git a/crates/router/src/core/errors/utils.rs b/crates/router/src/core/errors/utils.rsindex 869a5b6bde..b62abd0e33 100644--- a/crates/router/src/core/errors/utils.rs+++ b/crates/router/src/core/errors/utils.rs@@ -136,25 +136,81 @@ pub trait ConnectorErrorExt<T> {impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError> {fn to_refund_failed_response(self) -> error_stack::Result<T, errors::ApiErrorResponse> {- self.map_err(|err| {- let data = match err.current_context() {- errors::ConnectorError::ProcessingStepFailed(Some(bytes)) => {- let response_str = std::str::from_utf8(bytes);- match response_str {- Ok(s) => serde_json::from_str(s)- .map_err(- |error| logger::error!(%error,"Failed to convert response to JSON"),- )- .ok(),- Err(error) => {- logger::error!(%error,"Failed to convert response to UTF8 string");- None- }+ self.map_err(|err| match err.current_context() {+ errors::ConnectorError::ProcessingStepFailed(Some(bytes)) => {+ let response_str = std::str::from_utf8(bytes);+ let data = match response_str {+ Ok(s) => serde_json::from_str(s)+ .map_err(+ |error| logger::error!(%error,"Failed to convert response to JSON"),+ )+ .ok(),+ Err(error) => {+ logger::error!(%error,"Failed to convert response to UTF8 string");+ None}+ };+ err.change_context(errors::ApiErrorResponse::RefundFailed { data })+ }+ errors::ConnectorError::NotImplemented(reason) => {+ errors::ApiErrorResponse::NotImplemented {+ message: errors::api_error_response::NotImplementedMessage::Reason(+ reason.to_string(),+ ),}- _ => None,- };- err.change_context(errors::ApiErrorResponse::RefundFailed { data })+ .into()+ }+ 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::ProcessingStepFailed(_)+ | errors::ConnectorError::InvalidConnectorName+ | errors::ConnectorError::InvalidWallet+ | errors::ConnectorError::ResponseHandlingFailed+ | errors::ConnectorError::MissingRequiredField { .. }+ | errors::ConnectorError::MissingRequiredFields { .. }+ | errors::ConnectorError::FailedToObtainAuthType+ | errors::ConnectorError::FailedToObtainCertificate+ | errors::ConnectorError::NoConnectorMetaData+ | errors::ConnectorError::FailedToObtainCertificateKey+ | 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::InvalidConnectorConfig { .. } => {+ err.change_context(errors::ApiErrorResponse::RefundFailed { data: None })+ }})}