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

#report_exception_to_rollbar

Class Method Details

.included(base) ⇒ Object



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

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



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rollbar/middleware/rails/show_exceptions.rb', line 21

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

#extract_scope_from(env) ⇒ Object



34
35
36
37
38
39
# File 'lib/rollbar/middleware/rails/show_exceptions.rb', line 34

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

#render_exception_with_rollbar(env, exception) ⇒ Object



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

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