Class: Hyperdrive::Middleware::Error

Inherits:
Object
  • Object
show all
Includes:
Values
Defined in:
lib/hyperdrive/middleware/error.rb

Instance Method Summary collapse

Methods included from Values

default_config, default_cors_options, default_headers, definable_request_methods, http_request_methods, request_methods, supported_request_methods

Constructor Details

#initialize(app) ⇒ Error



8
9
10
# File 'lib/hyperdrive/middleware/error.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/hyperdrive/middleware/error.rb', line 12

def call(env)
  @app.call(env)
rescue Hyperdrive::Errors::HTTPError => e
  status = e.http_status_code
  headers = { 'Content-Type' => 'application/json',
              'Allow' => supported_request_methods.join(', ') }
  body = Oj.dump(error_message(e), mode: :compat)
  [status, headers, [body]]
end