Sha256: 9c8202e88c86bb33d26e17b91232256f7b86eeee2a60626dbfbdedf3ea44a76f

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

module Binnacle
  module Trap
    class Middleware

      def initialize(app)
        @app = app
      end

      def call(env)
        _, headers, _ = response = @app.call(env)
        response
      rescue Exception => exception
        if report?(exception, headers)
          begin
            Binnacle.binnacle_logger.debug "Binnacle: reporting exception: #{exception.class.name}"
            Binnacle.report_exception(exception, env)
          rescue
            # prevent the observer effect
          ensure
            raise
          end
        else
          raise
        end
      end

      def report?(exception, headers)
        exception_class_name = exception.class.name
        if Binnacle.configuration.trap?
          if Binnacle.configuration.ignore_cascade_pass?
            if headers && headers['X-Cascade']
              report = headers['X-Cascade'] != 'pass'
            else
              report = true
            end
          end
          Binnacle.configuration.ignored_exceptions.include?(exception_class_name) ? false : report
        else
          false
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
binnacle-0.5.0 lib/binnacle/trap/middleware.rb
binnacle-0.4.9 lib/binnacle/trap/middleware.rb
binnacle-0.4.8 lib/binnacle/trap/middleware.rb