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

chore: intoduce GenericError enum variant in enum ConnectorError #6189

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
2 changes: 1 addition & 1 deletion crates/drainer/src/health_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl HealthCheckInterface for Store {
logger::debug!("Redis set_key was successful");

redis_conn
.get_key("test_key")
.get_key::<()>("test_key")
.await
.change_context(HealthCheckRedisError::GetFailed)?;

Expand Down
5 changes: 5 additions & 0 deletions crates/hyperswitch_interfaces/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ pub enum ConnectorError {
InvalidConnectorConfig { config: &'static str },
#[error("Failed to convert amount to required type")]
AmountConversionFailed,
#[error("Generic Error")]
GenericError {
error_message: String,
error_object: serde_json::Value,
},
}

impl ConnectorError {
Expand Down
11 changes: 6 additions & 5 deletions crates/router/src/connector/globalpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,11 +1017,12 @@ impl api::IncomingWebhook for Globalpay {
&self,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
let details = std::str::from_utf8(request.body)
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
Ok(Box::new(serde_json::from_str(details).change_context(
errors::ConnectorError::WebhookResourceObjectNotFound,
)?))
Ok(Box::new(
request
.body
.parse_struct::<GlobalpayPaymentsResponse>("GlobalpayPaymentsResponse")
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?,
))
}
}

Expand Down
7 changes: 5 additions & 2 deletions crates/router/src/core/errors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
| errors::ConnectorError::RequestTimeoutReceived
| errors::ConnectorError::CurrencyNotSupported { .. }
| errors::ConnectorError::InvalidConnectorConfig { .. }
| errors::ConnectorError::AmountConversionFailed { .. } => {
| errors::ConnectorError::AmountConversionFailed { .. }
| errors::ConnectorError::GenericError { .. } => {
err.change_context(errors::ApiErrorResponse::RefundFailed { data: None })
}
})
Expand Down Expand Up @@ -311,6 +312,7 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
errors::ConnectorError::InSufficientBalanceInPaymentMethod |
errors::ConnectorError::RequestTimeoutReceived |
errors::ConnectorError::ProcessingStepFailed(None)|
errors::ConnectorError::GenericError {..} |
errors::ConnectorError::AmountConversionFailed => errors::ApiErrorResponse::InternalServerError
};
err.change_context(error)
Expand Down Expand Up @@ -402,7 +404,8 @@ impl<T> ConnectorErrorExt<T> for error_stack::Result<T, errors::ConnectorError>
| errors::ConnectorError::RequestTimeoutReceived
| errors::ConnectorError::CurrencyNotSupported { .. }
| errors::ConnectorError::ProcessingStepFailed(None)
| errors::ConnectorError::AmountConversionFailed { .. } => {
| errors::ConnectorError::AmountConversionFailed { .. }
| errors::ConnectorError::GenericError { .. } => {
logger::error!(%error,"Setup Mandate flow failed");
errors::ApiErrorResponse::PaymentAuthorizationFailed { data: None }
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/health_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl HealthCheckInterface for app::SessionState {
logger::debug!("Redis set_key was successful");

redis_conn
.get_key("test_key")
.get_key::<()>("test_key")
.await
.change_context(errors::HealthCheckRedisError::GetFailed)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ where
.to_validate_request()?
.validate_request(&req, &merchant_account)?;

tracing::Span::current().record("payment_id", &format!("{}", validate_result.payment_id));
tracing::Span::current().record("payment_id", format!("{}", validate_result.payment_id));

let operations::GetTrackerResponse {
operation,
Expand Down
65 changes: 0 additions & 65 deletions crates/router/src/services/connector_integration_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,71 +439,6 @@ impl api::ConnectorCommon for ConnectorEnum {
}
}

impl<T, ResourceCommonData, Req, Resp> api::ConnectorCommon
for ConnectorIntegrationEnum<'_, T, ResourceCommonData, Req, Resp>
{
fn id(&self) -> &'static str {
match self {
ConnectorIntegrationEnum::Old(old_integration) => old_integration.id(),
ConnectorIntegrationEnum::New(new_integration) => new_integration.id(),
}
}

fn get_currency_unit(&self) -> CurrencyUnit {
match self {
ConnectorIntegrationEnum::Old(old_integration) => old_integration.get_currency_unit(),
ConnectorIntegrationEnum::New(new_integration) => new_integration.get_currency_unit(),
}
}

fn get_auth_header(
&self,
auth_type: &types::ConnectorAuthType,
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
match self {
ConnectorIntegrationEnum::Old(old_integration) => {
old_integration.get_auth_header(auth_type)
}
ConnectorIntegrationEnum::New(new_integration) => {
new_integration.get_auth_header(auth_type)
}
}
}

fn common_get_content_type(&self) -> &'static str {
match self {
ConnectorIntegrationEnum::Old(old_integration) => {
old_integration.common_get_content_type()
}
ConnectorIntegrationEnum::New(new_integration) => {
new_integration.common_get_content_type()
}
}
}

fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str {
match self {
ConnectorIntegrationEnum::Old(old_integration) => old_integration.base_url(connectors),
ConnectorIntegrationEnum::New(new_integration) => new_integration.base_url(connectors),
}
}

fn build_error_response(
&self,
res: types::Response,
event_builder: Option<&mut ConnectorEvent>,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
match self {
ConnectorIntegrationEnum::Old(old_integration) => {
old_integration.build_error_response(res, event_builder)
}
ConnectorIntegrationEnum::New(new_integration) => {
new_integration.build_error_response(res, event_builder)
}
}
}
}

pub trait ConnectorIntegrationInterface<F, ResourceCommonData, Req, Resp>: Send + Sync {
fn clone_box(
&self,
Expand Down
18 changes: 0 additions & 18 deletions crates/router/src/types/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,54 +90,36 @@ pub trait Router {}
pub trait Connector:
Send
+ Refund
+ RefundV2
+ Payment
+ PaymentV2
+ ConnectorRedirectResponse
+ IncomingWebhook
+ ConnectorAccessToken
+ ConnectorAccessTokenV2
+ Dispute
+ DisputeV2
+ FileUpload
+ FileUploadV2
+ ConnectorTransactionId
+ Payouts
+ PayoutsV2
+ ConnectorVerifyWebhookSource
+ ConnectorVerifyWebhookSourceV2
+ FraudCheck
+ FraudCheckV2
+ ConnectorMandateRevoke
+ ConnectorMandateRevokeV2
+ ExternalAuthentication
+ ExternalAuthenticationV2
{
}

impl<
T: Refund
+ RefundV2
+ Payment
+ PaymentV2
+ ConnectorRedirectResponse
+ Send
+ IncomingWebhook
+ ConnectorAccessToken
+ ConnectorAccessTokenV2
+ Dispute
+ DisputeV2
+ FileUpload
+ FileUploadV2
+ ConnectorTransactionId
+ Payouts
+ PayoutsV2
+ ConnectorVerifyWebhookSource
+ ConnectorVerifyWebhookSourceV2
+ FraudCheck
+ FraudCheckV2
+ ConnectorMandateRevoke
+ ConnectorMandateRevokeV2
+ ExternalAuthentication
+ ExternalAuthenticationV2,
> Connector for T
Expand Down
4 changes: 1 addition & 3 deletions crates/router_env/tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn basic() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {

#[cfg(feature = "vergen")]
#[tokio::test]
async fn env_macro() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
async fn env_macro() {
println!("version : {:?}", env::version!());
println!("build : {:?}", env::build!());
println!("commit : {:?}", env::commit!());
Expand All @@ -33,6 +33,4 @@ async fn env_macro() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
assert!(!env::build!().is_empty());
assert!(!env::commit!().is_empty());
// assert!(env::platform!().len() > 0);

Ok(())
}
2 changes: 1 addition & 1 deletion crates/storage_impl/src/redis/pub_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
self.subscriber.manage_subscriptions();

self.subscriber
.subscribe(channel)
.subscribe::<(), &str>(channel)
.await
.change_context(redis_errors::RedisError::SubscribeError)?;

Expand Down
Loading