Class: Hanami::Webconsole::Middleware Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/webconsole/middleware.rb

Overview

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

Since:

  • 2.1.0

Defined Under Namespace

Modules: BetterErrorsExtension

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Middleware

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.

Returns a new instance of Middleware.

Since:

  • 2.1.0



43
44
45
46
47
48
# File 'lib/hanami/webconsole/middleware.rb', line 43

def initialize(app, config)
  @better_errors = BetterErrors::Middleware.new(app)
  @config = config

  configure_better_errors
end

Instance Method Details

#call(env) ⇒ 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.

Since:

  • 2.1.0



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hanami/webconsole/middleware.rb', line 52

def call(env)
  rescued_exception = nil
  env[CAPTURE_EXCEPTION_PROC_KEY] = -> ex { rescued_exception = ex }

  status, headers, body = @better_errors.call(env)

  # Replace the BetterErrors status with a properly configured one for the Hanami app
  if rescued_exception
    status = Rack::Utils.status_code(
      @config.render_error_responses[rescued_exception.class.name]
    )
  end

  [status, headers, body]
end