Class: PublicRescue::PublicExceptions3

Inherits:
Object
  • Object
show all
Defined in:
lib/public_rescue/public_exceptions3.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/public_rescue/public_exceptions3.rb', line 4

def call(env)

  exception = env["action_dispatch.exception"]
  wrapper = ActionDispatch::ExceptionWrapper.new(env, exception)

  request = ActionDispatch::Request.new(env)
  status = wrapper.status_code
  exception_details = {
          :request => request, :exception => exception,
          :status => status,
          :application_trace => wrapper.application_trace,
          :framework_trace => wrapper.framework_trace,
          :full_trace => wrapper.full_trace
  }
  request.env['public_rescue.exception_details'] = exception_details
  action = ActionDispatch::ExceptionWrapper.rescue_responses[exception.class.name]
  controller_name = Rails.configuration.public_rescue.controller.to_s.camelize << 'Controller'
  begin
    controller = Rails.const_get(controller_name)
  rescue NameError => n_E
    controller = PublicErrorsController
  end
  response = controller.action(action).call(request.env).last
  render(status, response.body)
end