Class: ActionDispatch::DebugExceptions

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

Instance Method Summary collapse

Instance Method Details

#render_exception(env, exception) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xilence.rb', line 6

def render_exception(env, exception)
  wrapper = ExceptionWrapper.new(env, exception)
  log_error(env, wrapper)

  if env['action_dispatch.show_detailed_exceptions']
    request = Request.new(env)

    if request.xhr?
      linebreaker = "\n  "

      title = "#{wrapper.exception.class} (#{wrapper.exception.message}):#{linebreaker}"

      trace = wrapper.application_trace
      trace = wrapper.framework_trace if trace.empty?
      trace = trace.join linebreaker

      render(500, title + trace)
    else
      template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
        :request => request,
        :exception => wrapper.exception,
        :application_trace => wrapper.application_trace,
        :framework_trace => wrapper.framework_trace,
        :full_trace => wrapper.full_trace
      )

      file = "rescues/#{wrapper.rescue_template}"
      body = template.render(:template => file, :layout => 'rescues/layout')
      render(wrapper.status_code, body)
    end
  else
    raise exception
  end
end