Sha256: 928a27d9916dd34259d040268fb42a7ee374a0de615b0d9ef5aeaef3886edbcb

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
#
# Original source:
# https://github.com/rails/rails/blob/4-1-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
#

ActionDispatch::DebugExceptions.class_eval do
  prepend(InertiaDebugExceptions = Module.new do
    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)
        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,
          routes_inspector: routes_inspector(exception),
          source_extract: wrapper.source_extract,
          line_number: wrapper.line_number,
          file: wrapper.file
        )
        file = "rescues/#{wrapper.rescue_template}"

        if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
          body = template.render(template: file, layout: false, formats: [:text])
          format = "text/plain"
        else
          body = template.render(template: file, layout: 'rescues/layout')
          format = "text/html"
        end
        render(wrapper.status_code, body, format)
      else
        raise exception
      end
    end
  end)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
inertia_rails-1.4.0 lib/patches/debug_exceptions/patch-4-1.rb
inertia_rails-1.3.1 lib/patches/debug_exceptions/patch-4-1.rb
inertia_rails-1.3.0 lib/patches/debug_exceptions/patch-4-1.rb
inertia_rails-1.2.2 lib/patches/debug_exceptions/patch-4-1.rb