1
0
mirror of https://github.com/danbee/danbarberphoto synced 2025-03-04 08:49:07 +00:00
danbarberphoto/vendor/plugins/exception_notification/lib/exception_notifier.rb
2010-10-14 07:10:25 -04:00

32 lines
948 B
Ruby

require 'action_dispatch'
require 'exception_notifier/notifier'
class ExceptionNotifier
def self.default_ignore_exceptions
[].tap do |exceptions|
exceptions << ActiveRecord::RecordNotFound if defined? ActiveRecord
exceptions << AbstractController::ActionNotFound if defined? AbstractController
exceptions << ActionController::RoutingError if defined? ActionController
end
end
def initialize(app, options = {})
@app, @options = app, options
@options[:ignore_exceptions] ||= self.class.default_ignore_exceptions
end
def call(env)
@app.call(env)
rescue Exception => exception
options = (env['exception_notifier.options'] ||= {})
options.reverse_merge!(@options)
unless Array.wrap(options[:ignore_exceptions]).include?(exception.class)
Notifier.exception_notification(env, exception).deliver
env['exception_notifier.delivered'] = true
end
raise exception
end
end