Harbor::ExceptionNotifier
Utility class for receiving email notifications of exceptions in non-development environments.
services.register("mailer", Harbor::Mailer)
services.register("mail_server", Harbor::SendmailServer)
require 'harbor/exception_notifier'
You will then receive email alerts for all 500 errors in the format of:
From: errors@request_host Subject: [ERROR] [request_host] [environment] Exception description Body: stack trace found in log, with request details.
Public Class Methods
notification_address()
# File lib/harbor/exception_notifier.rb, line 23 23: def self.notification_address 24: @@notification_address 25: rescue NameError 26: raise "Harbor::ExceptionMailer.notification_address not set." 27: end
notification_address=(address)
# File lib/harbor/exception_notifier.rb, line 19 19: def self.notification_address=(address) 20: @@notification_address = address 21: end
notification_address?()
# File lib/harbor/exception_notifier.rb, line 29 29: def self.notification_address? 30: defined?(@@notification_address) 31: end
notify(exception, request, response, trace)
# File lib/harbor/exception_notifier.rb, line 33 33: def self.notify(exception, request, response, trace) 34: return if request.environment == "development" 35: 36: mailer = request.application.services.get("mailer") 37: mailer.to = notification_address 38: 39: host = request.env["HTTP_X_FORWARDED_HOST"] || request.host 40: mailer.from = "errors@#{host}" 41: 42: subject = exception.to_s 43: 44: # We can't have multi-line subjects, so we chop off extra lines 45: if subject[$/] 46: subject = subject.split($/, 2)[0] + "..." 47: end 48: 49: mailer.subject = "[ERROR] [#{request.host}] [#{request.environment}] #{subject}" 50: mailer.text = trace 51: mailer.set_header("X-Priority", 1) 52: mailer.set_header("X-MSMail-Priority", "High") 53: mailer.send! 54: end