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

feat(api): Introduce new error #3215

Closed
wants to merge 1 commit into from

Conversation

julienbourdeau
Copy link
Contributor

Context

As I was working on adding crypto, I realized if the checkout URL failed, we just return an 200 response where the checkout url is incorrect.

Description

I sometimes find that the API swallow to many errors. You receive a webhook with all the details but the API will simply return a cryptic error code.

Here I'm thinking about adding a new kind of failure for Payment Provider.

A contributor recently introduced thirdparty_errors because there was no easy way to return error from another service. I don't like the name too much, we usually use "integrations" or "provider" rather than third parties but more importantly I think it's too limited to return only a message.

Please share anything you have in mind. I'm not too sure we should merge the PR in this state but I'd like the API to return more errors from payment provider.

Error before

CleanShot 2025-02-18 at 11 46 01@2x

Error after

CleanShot 2025-02-18 at 12 39 48@2x

@julienbourdeau julienbourdeau self-assigned this Feb 19, 2025
@julienbourdeau julienbourdeau force-pushed the feat/payment-provider-error branch from 1af5bd2 to 41c6850 Compare February 19, 2025 17:08
Copy link
Collaborator

@vincent-pochet vincent-pochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to put this topic on the table. I would just suggest to build a dedicated way to handle errors for all providers rather than adding a new logic just for payment providers.

My dream is to have a single way to handle failures for integrations:

  • Webhooks (with have 10 differents error webhooks, with different signatures...)
  • Error storing for display purpose in the front-end or the API, like it has been done for tax providers
  • API responses for sync actions
  • ...

Happy to discuss about it :)

@@ -93,6 +93,20 @@ def initialize(result, message:)
end
end

class PaymentProviderFailure < FailedResult
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are relying on many integration, I would suggest to rename the ThirdPartyFailure into IntegrationFailure and allow it to expose the initial error from the provider.

In many places in the project we have different ways of dealing with provider error, I'm not sure that adding a new one will simplify it 😄

@@ -203,6 +203,21 @@ def deliver_error_webhook(stripe_error)
)
end

def fail!(stripe_error)
result.fail_with_error!(PaymentProviderFailure.new(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the "easy" way, you could rely on result.provider_error!(...). That way, no need to build yourself the instance of the error at this stage

@@ -84,7 +84,7 @@ def generate_checkout_url(send_webhook: true)
result
rescue ::Stripe::InvalidRequestError, ::Stripe::PermissionError => e
deliver_error_webhook(e)
result
fail! e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups... Indeed, this one in this scope should not be swallowed... 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this separately so we can get it fixed today

@julienbourdeau
Copy link
Contributor Author

Closed in favor of #3247 and #3238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants