-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor(core): add error handling wrapper to wehbook #6636
base: main
Are you sure you want to change the base?
Conversation
Changed Files
|
crates/router/src/utils.rs
Outdated
@@ -1344,3 +1344,7 @@ pub async fn trigger_refund_outgoing_webhook( | |||
) -> RouterResult<()> { | |||
todo!() | |||
} | |||
|
|||
pub fn is_webhook_not_found_error(err: &errors::ApiErrorResponse) -> bool { | |||
matches!(err, errors::ApiErrorResponse::WebhookResourceNotFound) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add all the other NotFound errors which can occur like PaymentNotFound, RefundNotFound etc.
@@ -117,14 +117,104 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>( | |||
Ok(application_response) | |||
} | |||
|
|||
async fn incoming_webhooks_error_wrapper<W: types::OutgoingWebhookType>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we try to eliminate this wrapper?
@@ -282,6 +282,9 @@ impl Connector { | |||
pub fn is_pre_processing_required_before_authorize(&self) -> bool { | |||
matches!(self, Self::Airwallex) | |||
} | |||
pub fn should_connector_bypass_error_if_webhook_not_found(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn should_connector_bypass_error_if_webhook_not_found(&self) -> bool { | |
pub fn should_acknowledge_webhook_for_resource_not_found_errors(&self) -> bool { |
))) | ||
} else { | ||
Ok(services::api::ApplicationResponse::TextPlain( | ||
"[accepted]".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to send "[accepted]"
back in the response / any content body right?
state.clone(), | ||
req_state, | ||
req, | ||
merchant_account.clone(), | ||
key_store, | ||
connector_name_or_mca_id, | ||
merchant_connector_account, | ||
connector.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can try passing references here
let (application_response, webhooks_response_tracker, serialized_req) = | ||
Box::pin(incoming_webhooks_core::<W>( | ||
|
||
// Fetch the merchant connector account to get the webhooks source secret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also please add the comment why the mca and connector are being fetched in wrapper instead of core?
crates/router/src/utils.rs
Outdated
| errors::ApiErrorResponse::PayoutNotFound | ||
| errors::ApiErrorResponse::MandateNotFound | ||
| errors::ApiErrorResponse::PaymentNotFound | ||
| errors::ApiErrorResponse::RefundNotFound |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add errors::ApiErrorResponse::AuthenticationNotFound
error too
cc7f16c
to
2f81d72
Compare
| ApiErrorResponse::PaymentNotFound | ||
| ApiErrorResponse::RefundNotFound | ||
| ApiErrorResponse::AuthenticationNotFound { .. } => Self::ResourceNotFound, | ||
_ => Self::InternalError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we map everything else to an internal error, or should we only map InternalServerError
to InternalError
and everything else to an Unknown
error variant?
vec![( | ||
"x-http-code".to_string(), | ||
Maskable::Masked(Secret::new("404".to_string())), | ||
)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this custom header? If yes, then where would be monitoring this (Grafana dashboard, etc.)? Or can we have metrics instead?
Type of Change
Description
In webhook, for specific connectors, we want to consume every webhook that arrives even if a error occurs while processing. This is done to keep the webhook channel open with the connector.
In this pr, a error wrapper is introduced to handle this logic where based on connector, we choose whether to send error or not.
Additional Changes
Motivation and Context
How did you test it?
Tested through Postman:
Case 2:
ngrok
to intercept webhookpayout_attempt
from the payout_attempt table against the generatedpayout_id
x-http-code
present in headersChecklist
cargo +nightly fmt --all
cargo clippy