Class: Hyperdrive::Middleware::Error
- Inherits:
-
Object
- Object
- Hyperdrive::Middleware::Error
- Includes:
- Values
- Defined in:
- lib/hyperdrive/middleware/error.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Error
constructor
A new instance of Error.
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
Returns a new instance of 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 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hyperdrive/middleware/error.rb', line 12 def call(env) @app.call(env) rescue => e = "#{e.class}: #{e.}" $stdout.sync = true $stdout.puts headers = { 'Content-Type' => 'application/json' } if e.respond_to?(:http_status_code) status = e.http_status_code body = [json_error(e)] else status = 500 error = if ENV['RACK_ENV'] == 'production' Hyperdrive::Errors::UnknownError.new else Hyperdrive::Errors::UnknownError.new() end body = [json_error(error)] end [status, headers, body] end |