Module: Rollbar::Middleware::Rails::ShowExceptions

Includes:
ExceptionReporter
Defined in:
lib/rollbar/middleware/rails/show_exceptions.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ExceptionReporter

#capture_uncaught?, #exception_data, #log_exception_message, #report_exception_to_rollbar

Class Method Details

.included(base) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/rollbar/middleware/rails/show_exceptions.rb', line 50

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

Instance Method Details

#call_with_rollbar(env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rollbar/middleware/rails/show_exceptions.rb', line 26

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

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

  raise e
end

#extract_scope_from(env) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/rollbar/middleware/rails/show_exceptions.rb', line 39

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

  scope || {}
end

#render_exception_with_rollbar(env, exception, wrapper = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rollbar/middleware/rails/show_exceptions.rb', line 7

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

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

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

  # Rails 7.1 changes the method signature for render_exception.
  if self.class.instance_method(:render_exception_without_rollbar).arity == 2
    render_exception_without_rollbar(env, exception)
  else
    render_exception_without_rollbar(env, exception, wrapper)
  end
end