Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Error propagation for not supporting partial refund #2976

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions crates/router/src/connector/prophetpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,7 @@ impl<F> TryFrom<&ProphetpayRouterData<&types::RefundsRouterData<F>>> for Prophet
action_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())
}
}
}
Expand Down
90 changes: 73 additions & 17 deletions crates/router/src/core/errors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
})
}

Expand Down
Loading