Class: ExceptionNotifier
- Inherits:
-
Object
- Object
- ExceptionNotifier
- Defined in:
- lib/exception_notifier.rb,
lib/exception_notifier/notifier.rb
Defined Under Namespace
Classes: Notifier
Class Method Summary (collapse)
- + (Object) background_options
- + (Object) default_ignore_exceptions
- + (Object) with(options = {}, &block)
Instance Method Summary (collapse)
- - (Object) call(env)
-
- (ExceptionNotifier) initialize(app, options = {})
constructor
A new instance of ExceptionNotifier.
Constructor Details
- (ExceptionNotifier) initialize(app, options = {})
A new instance of ExceptionNotifier
28 29 30 31 |
# File 'lib/exception_notifier.rb', line 28 def initialize(app, = {}) @app, @options = app, @options[:ignore_exceptions] ||= self.class.default_ignore_exceptions end |
Class Method Details
+ (Object) background_options
14 15 16 |
# File 'lib/exception_notifier.rb', line 14 def @background_options ||= Rails.application.middleware.find { |klass| klass == ExceptionNotifier }.args.first rescue {} end |
+ (Object) default_ignore_exceptions
6 7 8 9 10 11 12 |
# File 'lib/exception_notifier.rb', line 6 def 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 |
+ (Object) with(options = {}, &block)
18 19 20 21 22 23 24 25 |
# File 'lib/exception_notifier.rb', line 18 def with( = {}, &block) block.call rescue Exception => exception unless Array.wrap([:ignore_exceptions]).include?(exception.class) Notifier.background_exception_notification(exception, ).deliver end raise exception end |
Instance Method Details
- (Object) call(env)
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/exception_notifier.rb', line 33 def call(env) @app.call(env) rescue Exception => exception = (env['exception_notifier.options'] ||= {}) .reverse_merge!(@options) unless Array.wrap([:ignore_exceptions]).include?(exception.class) Notifier.exception_notification(env, exception).deliver env['exception_notifier.delivered'] = true end raise exception end |