class Honeybadger::Rack::UserFeedback
Middleware for Rack
applications. Adds a feedback form to the Rack
response when an error has occurred.
Public Class Methods
new(app, agent = nil)
click to toggle source
# File lib/honeybadger/rack/user_feedback.rb, line 24 def initialize(app, agent = nil) @app = app @agent = agent.kind_of?(Agent) && agent end
Public Instance Methods
action()
click to toggle source
@private @todo Make this method and others actually private.
# File lib/honeybadger/rack/user_feedback.rb, line 46 def action URI.parse("#{config.connection_protocol}://#{config[:'connection.host']}:#{config.connection_port}/v1/feedback/").to_s rescue URI::InvalidURIError nil end
call(env)
click to toggle source
# 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
custom_template_file()
click to toggle source
@private
# File lib/honeybadger/rack/user_feedback.rb, line 59 def custom_template_file @custom_template_file ||= File.join(config[:root], 'lib', 'honeybadger', 'templates', 'feedback_form.erb') end
custom_template_file?()
click to toggle source
@private
# File lib/honeybadger/rack/user_feedback.rb, line 64 def custom_template_file? custom_template_file && File.exist?(custom_template_file) end
render_form(error_id, action = action())
click to toggle source
@private
# File lib/honeybadger/rack/user_feedback.rb, line 53 def render_form(error_id, action = action()) return unless action ERB.new(@template ||= File.read(template_file)).result(binding) end
template_file()
click to toggle source
@private
# File lib/honeybadger/rack/user_feedback.rb, line 69 def template_file if custom_template_file? custom_template_file else File.expand_path('../../templates/feedback_form.erb', __FILE__) end end
Private Instance Methods
agent()
click to toggle source
# File lib/honeybadger/rack/user_feedback.rb, line 82 def agent @agent || Honeybadger::Agent.instance end