Class: ExceptionNotification::Rack
- Inherits:
-
Object
- Object
- ExceptionNotification::Rack
- Defined in:
- lib/exception_notification/rack.rb
Defined Under Namespace
Classes: CascadePassException
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app, options = {}) ⇒ Rack
Returns a new instance of Rack.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/exception_notification/rack.rb', line 7 def initialize(app, = {}) @app = app ExceptionNotifier.tap do |en| en.ignored_exceptions = .delete(:ignore_exceptions) if .key?(:ignore_exceptions) en.error_grouping = .delete(:error_grouping) if .key?(:error_grouping) en.error_grouping_period = .delete(:error_grouping_period) if .key?(:error_grouping_period) en.notification_trigger = .delete(:notification_trigger) if .key?(:notification_trigger) if .key?(:error_grouping_cache) en.error_grouping_cache = .delete(:error_grouping_cache) elsif defined?(Rails) && Rails.respond_to?(:cache) en.error_grouping_cache = Rails.cache end end if .key?(:ignore_if) rack_ignore = .delete(:ignore_if) ExceptionNotifier.ignore_if do |exception, opts| opts.key?(:env) && rack_ignore.call(opts[:env], exception) end end if .key?(:ignore_notifier_if) rack_ignore_by_notifier = .delete(:ignore_notifier_if) rack_ignore_by_notifier.each do |notifier, proc| ExceptionNotifier.ignore_notifier_if(notifier) do |exception, opts| opts.key?(:env) && proc.call(opts[:env], exception) end end end ExceptionNotifier.ignore_crawlers(.delete(:ignore_crawlers)) if .key?(:ignore_crawlers) @ignore_cascade_pass = .delete(:ignore_cascade_pass) { true } .each do |notifier_name, opts| ExceptionNotifier.register_exception_notifier(notifier_name, opts) end end |
Instance Method Details
#call(env) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/exception_notification/rack.rb', line 48 def call(env) _, headers, = response = @app.call(env) if !@ignore_cascade_pass && headers['X-Cascade'] == 'pass' msg = "This exception means that the preceding Rack middleware set the 'X-Cascade' header to 'pass' -- in " \ 'Rails, this often means that the route was not found (404 error).' raise CascadePassException, msg end response rescue Exception => e env['exception_notifier.delivered'] = true if ExceptionNotifier.notify_exception(e, env: env) raise e unless e.is_a?(CascadePassException) response end |