Sha256: 97a923ebccb55590f75524925fea1f1dd675e23d70b4e22089b83bc1d3a0da33

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

module Chatterbox

  module RailsCatcher
    
    def self.included(base)
      if base.instance_methods.map(&:to_s).include? 'rescue_action_in_public' and !base.instance_methods.map(&:to_s).include? 'rescue_action_in_public_without_chatterbox'
        base.send(:alias_method, :rescue_action_in_public_without_chatterbox, :rescue_action_in_public)
        base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_chatterbox)
        base.hide_action(:rescue_action_in_public_with_chatterbox, :rescue_action_in_public_without_chatterbox)
      end
    end
    
    # Overrides the rescue_action method in ActionController::Base, but does not inhibit
    # any custom processing that is defined with Rails 2's exception helpers.
    def rescue_action_in_public_with_chatterbox exception
      Chatterbox.logger.debug { "#{self.class}#rescue_action_in_public_with_chatterbox: caught exception #{exception} - about to handle"}
      options = extract_exception_details(exception)
      Chatterbox.handle_notice(options)
      Chatterbox.logger.debug { "#{self.class}#rescue_action_in_public_with_chatterbox: handing exception #{exception} off to normal rescue handling"}
      
      rescue_action_in_public_without_chatterbox(exception)
    end
    
    def extract_exception_details(exception)
      options = { :exception => exception, :request => request }
      options = Chatterbox::ExceptionNotification::Extracter.wrap(options)
      options = Chatterbox::ExceptionNotification::RailsExtracter.wrap(options)
      options = Chatterbox::ExceptionNotification::Presenter.render(options)
      options
    end
    
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chatterbox-0.5.1 lib/chatterbox/rails_catcher.rb
chatterbox-0.5.0 lib/chatterbox/rails_catcher.rb