Class: ExceptionNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notifier.rb,
lib/exception_notifier/notifier.rb,
lib/exception_notifier/campfire_notifier.rb

Defined Under Namespace

Classes: CampfireNotifier, Notifier

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ExceptionNotifier.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/exception_notifier.rb', line 19

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

  Notifier.default_sender_address       = @options[:sender_address]
  Notifier.default_exception_recipients = @options[:exception_recipients]
  Notifier.default_email_prefix         = @options[:email_prefix]
  Notifier.default_email_format         = @options[:email_format]
  Notifier.default_sections             = @options[:sections]
  Notifier.default_background_sections  = @options[:background_sections]
  Notifier.default_verbose_subject      = @options[:verbose_subject]
  Notifier.default_normalize_subject    = @options[:normalize_subject]
  Notifier.default_smtp_settings        = @options[:smtp_settings]
  Notifier.default_email_headers        = @options[:email_headers]

  @campfire = CampfireNotifier.new @options[:campfire]

  @options[:ignore_exceptions] ||= self.class.default_ignore_exceptions
  @options[:ignore_crawlers]   ||= self.class.default_ignore_crawlers
  @options[:ignore_if]         ||= lambda { |env, e| false }
end

Class Method Details

.default_ignore_crawlersObject



15
16
17
# File 'lib/exception_notifier.rb', line 15

def self.default_ignore_crawlers
  []
end

.default_ignore_exceptionsObject



7
8
9
10
11
12
13
# File 'lib/exception_notifier.rb', line 7

def self.default_ignore_exceptions
  [].tap do |exceptions|
    exceptions << 'ActiveRecord::RecordNotFound'
    exceptions << 'AbstractController::ActionNotFound'
    exceptions << 'ActionController::RoutingError'
  end
end

Instance Method Details

#call(env) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/exception_notifier.rb', line 40

def call(env)
  @app.call(env)
rescue Exception => exception
  options = (env['exception_notifier.options'] ||= Notifier.default_options)
  options.reverse_merge!(@options)

  unless ignored_exception(options[:ignore_exceptions], exception)       ||
         from_crawler(options[:ignore_crawlers], env['HTTP_USER_AGENT']) ||
         conditionally_ignored(options[:ignore_if], env, exception)
    Notifier.exception_notification(env, exception).deliver
    @campfire.exception_notification(exception)
    env['exception_notifier.delivered'] = true
  end

  raise exception
end