Class: Honeybadger::Rack::UserFeedback

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/honeybadger/rack/user_feedback.rb

Overview

Middleware for Rack applications. Adds a feedback form to the Rack response when an error has occurred.

Instance Method Summary collapse

Constructor Details

#initialize(app, agent = nil) ⇒ UserFeedback

Returns a new instance of UserFeedback


24
25
26
27
# File 'lib/honeybadger/rack/user_feedback.rb', line 24

def initialize(app, agent = nil)
  @app = app
  @agent = agent.kind_of?(Agent) ? agent : Honeybadger::Agent.instance
end

Instance Method Details

#call(env) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/honeybadger/rack/user_feedback.rb', line 29

def call(env)
  return @app.call(env) unless config[:'feedback.enabled']
  status, headers, body = @app.call(env)
  if env['honeybadger.error_id'] && form = render_form(env['honeybadger.error_id'])
    new_body = []
    body.each do |chunk|
      new_body << chunk.gsub("<!-- HONEYBADGER FEEDBACK -->", form)
    end
    body.close if body.respond_to?(:close)
    headers['Content-Length'] = new_body.reduce(0) { |a,e| a += e.bytesize }.to_s
    body = new_body
  end
  [status, headers, body]
end