Sha256: 3d239850461414ae6a999e2f3aab8dff22436929bbaa44c5f1cb66c61b15cf70

Contents?: true

Size: 1.52 KB

Versions: 31

Compression:

Stored size: 1.52 KB

Contents

require 'honeybadger/plugin'

module Honeybadger
  module Plugins
    module Rails
      module ExceptionsCatcher
        # Adds additional Honeybadger info to Request env when an
        # exception is rendered in Rails' middleware.
        #
        # @param [Hash, ActionDispatch::Request] arg The Rack env +Hash+ in
        #   Rails 3.0-4.2. After Rails 5 +arg+ is an +ActionDispatch::Request+.
        # @param [Exception] exception The error which was rescued.
        #
        # @return The super value of the middleware's +#render_exception()+
        #   method.
        def render_exception(arg, exception)
          if arg.kind_of?(::ActionDispatch::Request)
            request = arg
            env = request.env
          else
            request = ::Rack::Request.new(arg)
            env = arg
          end

          env['honeybadger.exception'] = exception
          env['honeybadger.request.url'] = request.url rescue nil

          super(arg, exception)
        end
      end

      Plugin.register :rails_exceptions_catcher do
        requirement { defined?(::Rails.application) && ::Rails.application }

        execution do
          require 'rack/request'
          if defined?(::ActionDispatch::DebugExceptions)
            # Rails 3.2.x+
            ::ActionDispatch::DebugExceptions.prepend(ExceptionsCatcher)
          elsif defined?(::ActionDispatch::ShowExceptions)
            # Rails 3.0.x and 3.1.x
            ::ActionDispatch::ShowExceptions.prepend(ExceptionsCatcher)
          end
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
honeybadger-4.12.2 lib/honeybadger/plugins/rails.rb
honeybadger-4.12.1 lib/honeybadger/plugins/rails.rb
honeybadger-4.12.0 lib/honeybadger/plugins/rails.rb
honeybadger-4.11.0 lib/honeybadger/plugins/rails.rb
honeybadger-4.10.0 lib/honeybadger/plugins/rails.rb
honeybadger-4.9.0 lib/honeybadger/plugins/rails.rb
honeybadger-4.8.0 lib/honeybadger/plugins/rails.rb
honeybadger-4.7.3 lib/honeybadger/plugins/rails.rb
honeybadger-4.7.2 lib/honeybadger/plugins/rails.rb
honeybadger-4.7.1 lib/honeybadger/plugins/rails.rb
honeybadger-4.7.0 lib/honeybadger/plugins/rails.rb
honeybadger-4.6.0 lib/honeybadger/plugins/rails.rb
honeybadger-4.5.6 lib/honeybadger/plugins/rails.rb
honeybadger-4.5.5 lib/honeybadger/plugins/rails.rb
honeybadger-4.5.4 lib/honeybadger/plugins/rails.rb
honeybadger-4.5.3 lib/honeybadger/plugins/rails.rb
honeybadger-4.5.2 lib/honeybadger/plugins/rails.rb
honeybadger-4.5.1 lib/honeybadger/plugins/rails.rb
honeybadger-4.5.0 lib/honeybadger/plugins/rails.rb
honeybadger-4.4.2 lib/honeybadger/plugins/rails.rb