Class: Hanami::Middleware::PublicErrorsApp Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/middleware/public_errors_app.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.

The errors app given to RenderErrors, which renders error responses from HTML pages kept in ‘public/` as simple JSON structures.

See Also:

Since:

  • 2.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_path) ⇒ PublicErrorsApp

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 PublicErrorsApp.

Since:

  • 2.1.0



21
22
23
# File 'lib/hanami/middleware/public_errors_app.rb', line 21

def initialize(public_path)
  @public_path = public_path
end

Instance Attribute Details

#public_pathObject (readonly)

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



17
18
19
# File 'lib/hanami/middleware/public_errors_app.rb', line 17

def public_path
  @public_path
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



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hanami/middleware/public_errors_app.rb', line 27

def call(env)
  request = Rack::Request.new(env)
  status = request.path_info[1..].to_i
  content_type = request.get_header("HTTP_ACCEPT")

  default_body = {
    status: status,
    error: Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500])
  }

  render(status, content_type, default_body)
end