Class: RuntimeerrorNotifier::Notifier

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
lib/runtimeerror_notifier/notifier.rb

Constant Summary collapse

API_ENDPOINT =
ENV['RUNTIMEERROR_URL'] || "http://js.runtimeerror.net/incoming_emails"
SENDER_ADDRESS =
'[email protected]'
RECIPIENTS =
[]
SECTIONS =
%w(request session environment backtrace)
TEMPLATE_NAME =
'runtimeerror_notifier'
IGNORED_EXCEPTIONS =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(*emails) ⇒ Object



19
20
21
22
23
24
# File 'lib/runtimeerror_notifier/notifier.rb', line 19

def self.for(*emails)
  RECIPIENTS.push(*emails)
  RECIPIENTS.reject! {|s| s.to_s.strip.empty? }
  RECIPIENTS.uniq!
  $stderr.puts "WARNING [RuntimeerrorNotifier.for]: No email recipients configured" if $DEBUG && RECIPIENTS.empty?
end

.notification(env, exception, options = {}) ⇒ Object



26
27
28
# File 'lib/runtimeerror_notifier/notifier.rb', line 26

def self.notification(env, exception, options={})
  self.notification_mail(env, exception, options).try(:deliver_later) # Rails 4.2
end

Instance Method Details

#notification_mail(env, exception, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/runtimeerror_notifier/notifier.rb', line 30

def notification_mail(env, exception, options={})
  original_exception = if exception.respond_to?(:original_exception)
    exception.original_exception
  elsif exception.respond_to?(:continued_exception)
    exception.continued_exception
  else
    exception
  end
  case exception.class.name
  when *IGNORED_EXCEPTIONS
    # ignore
  else
    email = compose_email(env, original_exception, options)
    make_request(email)
    email.try(:perform_deliveries=, false)
  end
end