Sha256: 7161704c0a7d974e3fdf0617bf1bfda597c0ccff8385937139f89d400ee67f7e

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

# Adapted from Airbrake code https://github.com/airbrake/airbrake/blob/master/lib/airbrake/rails/action_controller_catcher.rb
module YogiBerra
  module ActionControllerCatcher
    # Sets up an alias chain to catch exceptions for Rails 2
    def self.included(base)
      YogiBerra::Catcher.quick_connection(true)
      if base.method_defined?(:rescue_action_in_public)
        base.send(:alias_method, :rescue_action_in_public_without_yogi, :rescue_action_in_public)
        base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_yogi)
        if YogiBerra::Catcher.settings
          base.send(:alias_method, :rescue_action_locally_without_yogi, :rescue_action_locally)
          base.send(:alias_method, :rescue_action_locally, :rescue_action_locally_with_yogi)
        end
      end
    end

    private
    # 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_yogi(exception)
      rescue_action_yogi(exception)
      rescue_action_in_public_without_yogi(exception)
    end

    def rescue_action_locally_with_yogi(exception)
      rescue_action_yogi(exception)
      rescue_action_locally_without_yogi(exception)
    end

    def rescue_action_yogi(exception)
        environment = {
          :session => session,
          :params => params,
          :user_agent => request.headers['HTTP_USER_AGENT'],
          :server_name => request.headers['SERVER_NAME'],
          :server_port => request.headers['SERVER_PORT'],
          :server_address => request.headers['SERVER_ADDR'],
          :remote_address => request.remote_ip
        }
      error_id = YogiBerra.exceptionize(exception, environment)
      request.env['yogi_berra.error_id'] = error_id
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yogi_berra-0.0.5 lib/yogi_berra/action_controller_catcher.rb