Class: ProjectlockerErrata::Rack
- Defined in:
- lib/projectlocker_errata/rack.rb
Overview
Middleware for Rack applications. Any errors raised by the upstream application will be delivered to ProjectlockerErrata and re-raised.
Synopsis:
require 'rack'
require 'projectlocker_errata'
ProjectlockerErrata.configure do |config|
config.api_key = 'my_api_key'
end
app = Rack::Builder.app do
run lambda { |env| raise "Rack down" }
end
use ProjectlockerErrata::Rack
run app
Use a standard ProjectlockerErrata.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_projectlocker_errata(exception, env) ⇒ Object
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
23 24 25 |
# File 'lib/projectlocker_errata/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 |
# File 'lib/projectlocker_errata/rack.rb', line 39 def call(env) begin response = @app.call(env) rescue Exception => raised env['projectlocker_errata.error_id'] = notify_projectlocker_errata(raised,env) raise end if env['rack.exception'] env['projectlocker_errata.error_id'] = notify_projectlocker_errata(env['rack.exception'],env) end response end |
#ignored_user_agent?(env) ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'lib/projectlocker_errata/rack.rb', line 27 def ignored_user_agent?(env) true if ProjectlockerErrata. configuration. ignore_user_agent. flatten. any? { |ua| ua === env['HTTP_USER_AGENT'] } end |
#notify_projectlocker_errata(exception, env) ⇒ Object
35 36 37 |
# File 'lib/projectlocker_errata/rack.rb', line 35 def notify_projectlocker_errata(exception,env) ProjectlockerErrata.notify_or_ignore(exception,:rack_env => env) unless ignored_user_agent?(env) end |