Sha256: 1c6e73105bb0dd228649bfb1cc9c12ffd283468cadfe390ac26bdf2abfbbd096

Contents?: true

Size: 938 Bytes

Versions: 1

Compression:

Stored size: 938 Bytes

Contents

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

module InertiaRails
  module InertiaDebugExceptions
    def render_for_default_application(request, wrapper)
      template = create_template(request, wrapper)
      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)
    end
  end
end

if defined?(ActionDispatch::DebugExceptions)
  ActionDispatch::DebugExceptions.prepend InertiaRails::InertiaDebugExceptions
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inertia_rails-3.5.0 lib/patches/debug_exceptions/patch-5-0.rb