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

How do you manage responses? #131

Open
amex-doug opened this issue Apr 23, 2020 · 3 comments
Open

How do you manage responses? #131

amex-doug opened this issue Apr 23, 2020 · 3 comments

Comments

@amex-doug
Copy link

I didn't see this in the documentation, but how does this library respond with 400s?

@maltesa
Copy link

maltesa commented Apr 24, 2020

I was wondering about that too. For me it seems that it is not possible to control the response code.
In the webhook controller matching hooks are called and 200 ok responsive is returned.

def event
      StripeEvent.instrument(verified_event)
      head :ok
 rescue Stripe::SignatureVerificationError => e
      log_error(e)
      head :bad_request
 end

Isn't it a common use case to return error codes if something goes wrong? In my case I convert a user to a premium user for incoming 'checkout.session.completed' events. If that failes I would like to return a 422 or something similar.

Update

I think a problem is that an event can have many subscribers. Each may set a different response code. I tried to solve that by using an exception. I implemented it testwise (#132) but I think it breaks the processing of the event by other subscribers. So it is probably not a good solution. Just wanted to reference it here.

@dmz006
Copy link

dmz006 commented Jan 18, 2021

I'm the first to admit I'm a hack coder so maybe I don't grok how different subscribers would break this. I'm testing out a slight change to your patch #132 but made a slight change to your webhook controller for ProcessError:

rescue Stripe::SignatureVerificationError => e
  log_error(e)
  head :bad_request
rescue StripeEvent::ProcessError => e
  head e.message.to_i
end

And I'm calling it by raising the error similar to yours but passing through the return code I want sent:
raise StripeEvent::ProcessError.new(400)

So far it's working in my tests and I can customize the header by just sending a valid response code number.

@rromanchuk
Copy link

I'm also struggling to find a clean way to extend this controller, i realized these webhooks were failing to get tagged properly as i'm not appending needed params for lograge https://github.com/roidrage/lograge

# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  def append_info_to_payload(payload)
    super
    payload[:service] = :stripe
   # ...truncated
  end
end

pretty reasonable. anyone happy with their implementation of something similar?

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

No branches or pull requests

4 participants