Class: ExceptionNotification::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notification/rack.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Rack

Returns a new instance of Rack.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/exception_notification/rack.rb', line 3

def initialize(app, options = {})
  @app = app

  ExceptionNotifier.ignored_exceptions = options.delete(:ignore_exceptions) if options.key?(:ignore_exceptions)

  if options.key?(:ignore_if)
    rack_ignore = options.delete(:ignore_if)
    ExceptionNotifier.ignore_if do |exception, options|
      options.key?(:env) && rack_ignore.call(options[:env], exception)
    end
  end

  if options.key?(:ignore_crawlers)
    ignore_crawlers = options.delete(:ignore_crawlers)
    ExceptionNotifier.ignore_if do |exception, options|
      options.key?(:env) && from_crawler(options[:env], ignore_crawlers)
    end
  end

  options.each do |notifier_name, options|
    ExceptionNotifier.register_exception_notifier(notifier_name, options)
  end
end

Instance Method Details

#call(env) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/exception_notification/rack.rb', line 27

def call(env)
  @app.call(env)
rescue Exception => exception
  if ExceptionNotifier.notify_exception(exception, :env => env)
    env['exception_notifier.delivered'] = true
  end
  raise exception
end