Class: Angus::Middleware::ExceptionHandler
- Inherits:
-
Object
- Object
- Angus::Middleware::ExceptionHandler
- 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_UNPROCESSABLE_ENTITY
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
-
#initialize(app, definitions = nil) ⇒ ExceptionHandler
constructor
A new instance of ExceptionHandler.
Methods included from StatusCodes
Constructor Details
#initialize(app, definitions = nil) ⇒ ExceptionHandler
Returns a new instance of ExceptionHandler.
11 12 13 14 |
# File 'lib/angus/middleware/exception_handler.rb', line 11 def initialize(app, definitions = nil) @app = app @definition_reader = Angus::DefinitionReader.new(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 |