Class: Honeybadger::Rack::ErrorNotifier

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

Overview

Middleware for Rack applications. Any errors raised by the upstream application will be delivered to Honeybadger and re-raised.

Examples:

require 'honeybadger/rack/error_notifier'

app = Rack::Builder.app do
  run lambda { |env| raise "Rack down" }
end

use Honeybadger::Rack::ErrorNotifier

run app

Instance Method Summary collapse

Constructor Details

#initialize(app, agent = nil) ⇒ ErrorNotifier

Returns a new instance of ErrorNotifier.



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

def initialize(app, agent = nil)
  @app = app
  @agent = agent.kind_of?(Agent) && agent
end

Instance Method Details

#call(env) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/honeybadger/rack/error_notifier.rb', line 29

def call(env)
  agent.with_rack_env(env) do
    begin
      env['honeybadger.config'] = config
      response = @app.call(env)
    rescue Exception => raised
      env['honeybadger.error_id'] = notify_honeybadger(raised, env)
      raise
    end

    framework_exception = framework_exception(env)
    if framework_exception
      env['honeybadger.error_id'] = notify_honeybadger(framework_exception, env)
    end

    response
  end
ensure
  agent.clear!
end