Sha256: 3b539b7c38aa860e3282c9cb549b6f118022f60bf4d5e1e5fb40811bf1e8d07d

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

module ExceptionNotification
  class Rack
    def initialize(app, options = {})
      @app = app

      ExceptionNotifier.ignored_exceptions = options.delete(:ignore_exceptions) if options.key?(:ignore_exceptions)

      if options.key?(:ignore_if)
        rack_ignore = options.delete(:ignore_if)
        ExceptionNotifier.ignore_if do |exception, options|
          options.key?(:env) && rack_ignore.call(options[:env], exception)
        end
      end

      if options.key?(:ignore_crawlers)
        ignore_crawlers = options.delete(:ignore_crawlers)
        ExceptionNotifier.ignore_if do |exception, options|
          options.key?(:env) && from_crawler(options[:env], ignore_crawlers)
        end
      end

      options.each do |notifier_name, options|
        ExceptionNotifier.register_exception_notifier(notifier_name, options)
      end
    end

    def call(env)
      @app.call(env)
    rescue Exception => exception
      if ExceptionNotifier.notify_exception(exception, :env => env)
        env['exception_notifier.delivered'] = true
      end
      raise exception
    end

    private

    def from_crawler(env, ignored_crawlers)
      agent = env['HTTP_USER_AGENT']
      Array(ignored_crawlers).any? do |crawler|
        agent =~ Regexp.new(crawler)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
exception_notification-4.1.0.rc1 lib/exception_notification/rack.rb
exception_notification-4.0.1 lib/exception_notification/rack.rb
exception_notification-4.0.0 lib/exception_notification/rack.rb
exception_notification-4.0.0.rc1 lib/exception_notification/rack.rb