ActionDispatch::DebugExceptions.class_eval do
  def render_exception_with_web_console(env, exception)
    render_exception_without_web_console(env, exception).tap do
      error = ActionDispatch::ExceptionWrapper.new(env, exception).exception

      # Get the original exception if ExceptionWrapper decides to follow it.
      env['web_console.exception'] = error

      # ActionView::Template::Error bypass ExceptionWrapper original
      # exception following. The backtrace in the view is generated from
      # reaching out to original_exception in the view.
      if error.is_a?(ActionView::Template::Error)
        env['web_console.exception'] = error.original_exception
      end
    end
  end

  alias_method :render_exception_without_web_console, :render_exception
  alias_method :render_exception, :render_exception_with_web_console
end

ActionDispatch::DebugExceptions.class_eval do
  def render_exception_with_web_console(request, exception)
    render_exception_without_web_console(request, exception).tap do
      backtrace_cleaner = request.env['action_dispatch.backtrace_cleaner']
      error = ActionDispatch::ExceptionWrapper.new(backtrace_cleaner, exception).exception

      # Get the original exception if ExceptionWrapper decides to follow it.
      request.env['web_console.exception'] = error

      # ActionView::Template::Error bypass ExceptionWrapper original
      # exception following. The backtrace in the view is generated from
      # reaching out to original_exception in the view.
      if error.is_a?(ActionView::Template::Error)
        request.env['web_console.exception'] = error.original_exception
      end
    end
  end

  alias_method :render_exception_without_web_console, :render_exception
  alias_method :render_exception, :render_exception_with_web_console
end

Fix method signature of exceptions
Fix method signature of exceptions

In 6d85804 the method signature of `render_exception` was changed to
require the `request` instead of the `env` and the `ExceptionWrapper`
was changed to take a `backtrace_cleaner` instead of the `env`.

This required changes to this method to a) get the `backtrace_cleaner`
from the request env and then to change calls to `env` to be calls to
`request.env`.

This bug had caused an issue where if there were exceptions on load like
pending migrations the error page and console would not be shown to the
user and instead they would only see the error in their log and in the
browser would be the Rails static 500 page "something went wrong".
