integrallis / stripe_event

Stripe webhook integration for Rails applications.
https://rubygems.org/gems/stripe_event
MIT License
840 stars 107 forks source link

return 500 explicitly #78

Closed peco8 closed 7 years ago

peco8 commented 7 years ago

Within a webhook, I sometimes need to expand the object for stripe (Request to Stripe for some values based on the request.)

At this point, if request fails for time out error, I'd love to return 500 explicitly.

  def retrieve_charge_metadata_of(invoice_metadata)
    return Stripe::Charge.retrieve(id: invoice_metadata.charge)
  rescue *EXTERNAL_CARD_ERRORS => e
    ExternalCardErrorHandler.new(e).handle
    head 500
  end

How can I achieve this with stripe-event? Or doe this automatically return 500 if something goes wrong? (Stripe::StripeError?)

invisiblefunnel commented 7 years ago

Raising an error that is not StripeEvent::UnauthorizedError should return a 500 error. It should be straightforward to test this.

peco8 commented 7 years ago

Hi this is closed but I'd love to check my understanding. So you mean I don't really need to rescue the error here. So instead of rescuing errors, I should let it blow up?

invisiblefunnel commented 7 years ago

It sounds like you have some error handling logic that needs to happen, so it makes sense that you'd need to rescue specific errors. If you need the webhook to be retried by Stripe you can re-raise after handling.

begin
  do_stuff
rescue => e
  handle(e)
  raise  # re-raise the exception.
end
peco8 commented 7 years ago

@invisiblefunnel Oh exactly! Thanks!