Class: RailsSpotlight::Middlewares::MainRequestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_spotlight/middlewares/main_request_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ MainRequestHandler

Returns a new instance of MainRequestHandler.



8
9
10
# File 'lib/rails_spotlight/middlewares/main_request_handler.rb', line 8

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



12
13
14
# File 'lib/rails_spotlight/middlewares/main_request_handler.rb', line 12

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rails_spotlight/middlewares/main_request_handler.rb', line 14

def call(env)
  app_request = AppRequest.new env['action_dispatch.request_id']
  app_request.current!
  app.call(env)
rescue StandardError => e
  if defined?(ActionDispatch::ExceptionWrapper)
    wrapper = if ActionDispatch::ExceptionWrapper.method_defined? :env
                ActionDispatch::ExceptionWrapper.new(env, e)
              else
                ActionDispatch::ExceptionWrapper.new(env['action_dispatch.backtrace_cleaner'], e)
              end
    app_request.events.push(*Event.events_for_exception(wrapper))
  else
    app_request.events.push(*Event.events_for_exception(e))
  end
  raise
ensure
  Storage.new(app_request.id).write(app_request.events.to_json) unless app_request.events.empty?
end