Module: Hanami::Webconsole::Middleware::BetterErrorsExtension Private

Defined in:
lib/hanami/webconsole/middleware.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

See Also:

Since:

  • 2.1.0

Instance Method Summary collapse

Instance Method Details

#show_error_page(env, exception = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The BetterErrors middleware always returns a 500 status when rescuing an exception (outside of Rails). This is not not always appropriate, such as for a ‘Hanami::Router::NotFoundError`, which should be a 404.

To account for this, gently patch ‘BetterErrors::Middleware#show_error_page` (which is called only when an exception has been rescued) to pass that rescued exception to a proc we inject into the rack env here in our own middleware. This allows our middleware to know the about exception class and provide the correct status code after BetterErrors is done with its job.

See Also:

Since:

  • 2.1.0



31
32
33
34
35
36
37
# File 'lib/hanami/webconsole/middleware.rb', line 31

def show_error_page(env, exception = nil)
  if (capture_proc = env[CAPTURE_EXCEPTION_PROC_KEY])
    capture_proc.call(exception)
  end

  super
end