Class: ActiveTracker::ExceptionCapturer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_tracker/exception_capturer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ExceptionCapturer

Returns a new instance of ExceptionCapturer.



3
4
5
# File 'lib/active_tracker/exception_capturer.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_tracker/exception_capturer.rb', line 7

def call(env)

  response = @app.call(env)

  framework_exception = env['action_dispatch.exception']
  if framework_exception
    record_exception(env, framework_exception)
  end

  response
rescue Exception => exception

  record_exception(env, exception)
  raise exception
end

#record_exception(env, exception) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_tracker/exception_capturer.rb', line 23

def record_exception(env, exception)
  if env['action_dispatch.backtrace_cleaner']
    backtrace = env['action_dispatch.backtrace_cleaner'].filter(exception.backtrace)
    backtrace = exception.backtrace if backtrace.blank?
  else
    backtrace = exception.backtrace
  end
  class_name = exception.class.name
  message = exception.message
  backtrace = backtrace || []

  ActiveTracker::Plugin::Exception.exception_capture(class_name, message, backtrace)
end