Class: Angus::Middleware::ExceptionHandler

Inherits:
Object
  • Object
show all
Includes:
StatusCodes
Defined in:
lib/angus/middleware/exception_handler.rb

Constant Summary

Constants included from StatusCodes

StatusCodes::HTTP_STATUS_CODE_CONFLICT, StatusCodes::HTTP_STATUS_CODE_FORBIDDEN, StatusCodes::HTTP_STATUS_CODE_INTERNAL_SERVER_ERROR, StatusCodes::HTTP_STATUS_CODE_NOT_FOUND, StatusCodes::HTTP_STATUS_CODE_OK, StatusCodes::HTTP_STATUS_CODE_UNAUTHORIZED, StatusCodes::HTTP_STATUS_CODE_UNPROCESSABLE_ENTITY

Instance Method Summary collapse

Methods included from StatusCodes

included

Constructor Details

#initialize(app) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



11
12
13
14
# File 'lib/angus/middleware/exception_handler.rb', line 11

def initialize(app)
  @app = app
  @definition_reader = Angus::DefinitionReader.new(app.base_middleware.definitions)
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
# File 'lib/angus/middleware/exception_handler.rb', line 16

def call(env)
  dup.call!(env)
end

#call!(env) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/angus/middleware/exception_handler.rb', line 20

def call!(env)
  @app.call(env)
rescue Exception => exception
  [
    status_code(exception),
    { 'Content-Type' => 'application/json' },
    [build_error_response(exception)]
  ]
end