Sha256: b649b9b3861e0ca404043a644b2c13567f83070f6b3658a2adc3b02ac5748d00

Contents?: true

Size: 857 Bytes

Versions: 6

Compression:

Stored size: 857 Bytes

Contents

module Airbrake
  class UserInformer
    def initialize(app)
      @app = app
    end

    def replacement(with)
      Airbrake.configuration.user_information.gsub(/\{\{\s*error_id\s*\}\}/, with.to_s)
    end

    def call(env)
      dup._call(env)
    end

    def _call(env)
      status, headers, body = @app.call(env)

      if env['airbrake.error_id'] && Airbrake.configuration.user_information
        new_body = []
        replace  = replacement(env['airbrake.error_id'])
        body.each do |chunk|
          new_body << chunk.gsub("<!-- AIRBRAKE ERROR -->", replace)
        end
        body.close if body.respond_to?(:close)
        headers['Content-Length'] = new_body.sum(&:bytesize).to_s
        body = new_body
      end

      [status, headers, body]

    ensure
      body.close if body && body.respond_to?(:close) && $!
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
airbrake-3.1.12 lib/airbrake/user_informer.rb
airbrake-3.1.11 lib/airbrake/user_informer.rb
airbrake-3.1.10 lib/airbrake/user_informer.rb
airbrake-3.1.9 lib/airbrake/user_informer.rb
airbrake-3.1.8 lib/airbrake/user_informer.rb
airbrake-3.1.7 lib/airbrake/user_informer.rb