Sha256: d07df091c40186f6b0b0b40233929e6ee6714a891c889aa5660339827d986b81

Contents?: true

Size: 1.49 KB

Versions: 50

Compression:

Stored size: 1.49 KB

Contents

module Rollbar
  module Middleware
    module Rails
      module ShowExceptions
        include ExceptionReporter

        def render_exception_with_rollbar(env, exception)
          key = 'action_dispatch.show_detailed_exceptions'

          if exception.is_a?(ActionController::RoutingError) && env[key]
            scope = extract_scope_from(env)

            Rollbar.scoped(scope) do
              report_exception_to_rollbar(env, exception)
            end
          end

          render_exception_without_rollbar(env, exception)
        end

        def call_with_rollbar(env)
          call_without_rollbar(env)
        rescue ActionController::RoutingError => exception
          # won't reach here if show_detailed_exceptions is true
          scope = extract_scope_from(env)

          Rollbar.scoped(scope) do
            report_exception_to_rollbar(env, exception)
          end

          raise exception
        end

        def extract_scope_from(env)
          scope = env['rollbar.scope']
          Rollbar.log_warn('[Rollbar] rollbar.scope key has been removed from Rack env.') unless scope

          scope || {}
        end

        def self.included(base)
          base.send(:alias_method, :call_without_rollbar, :call)
          base.send(:alias_method, :call, :call_with_rollbar)

          base.send(:alias_method, :render_exception_without_rollbar, :render_exception)
          base.send(:alias_method, :render_exception, :render_exception_with_rollbar)
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
rollbar-3.2.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-3.1.2 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-3.1.1 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-3.1.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-3.0.1 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-3.0.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.27.1 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.27.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.26.1 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.26.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.25.1 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.25.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.24.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.23.2 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.23.1 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.23.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.22.1 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.22.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.21.0 lib/rollbar/middleware/rails/show_exceptions.rb
rollbar-2.20.2 lib/rollbar/middleware/rails/show_exceptions.rb