chargebee / chargebee-rails-subscriptions

MIT License
6 stars 12 forks source link

NoMethodErrors on unhandled webhook events #3

Closed ghiculescu closed 6 years ago

ghiculescu commented 7 years ago

We're seeing a lot of errors like this when using this gem's standard webhook implementation:

image

My current solution is to override the controller in a fairly dodgy fashion:

class ChargebeeWebhooksWithRescueController < ChargebeeRails::WebhooksController
  def handle_event
    super
  rescue NoMethodError => e
    # undefined method because we don't respond to the given webhook
    log_errors(e)
    head :ok
  end
end

Is there a better/proper solution?

anton-ko commented 7 years ago

Hey @ghiculescu

I've ended up monkey patching the WebhookHandler in like this:

app/services/chargebee_rails/webhook_handler.rb

Rails.application.config.to_prepare do
  ChargebeeRails::WebhookHandler.module_eval do
    def handle(chargebee_event)
      @chargebee_event = chargebee_event
      sync_events if sync_events_list.include?(event.event_type)
      send(event.event_type) if respond_to?(event.event_type)
      # ignore events that aren't handled or add some logging
    end
  end
end
ConfusedVorlon commented 6 years ago

fyi - I have offered a similar solution in this pull request https://github.com/spritlesoftware/chargebee-rails-subscriptions/pull/13

Thirumal-Sakthivel commented 6 years ago

@ghiculescu We have handled only some important events initially. We will update the gem to handle all events. FYI: We will maintain this gem on SpritleSoftware repo and review and merge necessary PR over there. I am closing this issue here.