Class: Batbugger::Rack
- Inherits:
-
Object
- Object
- Batbugger::Rack
- Defined in:
- lib/batbugger/rack.rb
Overview
Middleware for Rack applications. Any errors raised by the upstream application will be delivered to Batbugger and re-raised.
Synopsis:
require 'rack'
require 'batbugger'
Batbugger.configure do |config|
config.api_key = 'my_api_key'
end
app = Rack::Builder.app do
run lambda { |env| raise "Rack down" }
end
use Batbugger::Rack
run app
Use a standard Batbugger.configure call to configure your api key.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #ignored_user_agent?(env) ⇒ Boolean
-
#initialize(app) ⇒ Rack
constructor
A new instance of Rack.
- #notify_batbugger(exception, env) ⇒ Object
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
23 24 25 |
# File 'lib/batbugger/rack.rb', line 23 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/batbugger/rack.rb', line 39 def call(env) begin response = @app.call(env) rescue Exception => raised env['batbugger.error_id'] = notify_batbugger(raised, env) raise ensure Batbugger.context.clear! end framework_exception = env['rack.exception'] || env['sinatra.error'] if framework_exception env['batbugger.error_id'] = notify_batbugger(framework_exception, env) end response end |
#ignored_user_agent?(env) ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'lib/batbugger/rack.rb', line 27 def ignored_user_agent?(env) true if Batbugger. configuration. ignore_user_agent. flatten. any? { |ua| ua === env['HTTP_USER_AGENT'] } end |
#notify_batbugger(exception, env) ⇒ Object
35 36 37 |
# File 'lib/batbugger/rack.rb', line 35 def notify_batbugger(exception,env) Batbugger.notify_or_ignore(exception, :rack_env => env) unless ignored_user_agent?(env) end |