1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- # coding=utf-8
- from pyramid.httpexceptions import HTTPNotFound
-
- from tracim import TracimRequest
- from tracim.extensions import hapic
- from tracim.views.controllers import Controller
- from tracim.views.errors import Error
- from pyramid.config import Configurator
-
-
- class DefaultController(Controller):
-
- def notfound_view(
- self,
- exception: HTTPNotFound,
- request: TracimRequest
- ):
- """
- Catch Not Found Exception
- :param exception: Exception Object
- :param request: current Request
- :return: 500 Internal Server Error with same format as others errors
- """
- request.response.status = 404
- return hapic.context.get_default_error_builder().build_from_exception(
- exception=exception
- )
-
- def exception_view(
- self,
- exception: Exception,
- request: TracimRequest
- ):
- """
- Catch all exceptions not handled in view
- :param exception: Exception Object
- :param request: current Request
- :return: 500 Internal Server Error with same format as others errors
- """
- request.response.status = 500
- return hapic.context.get_default_error_builder().build_from_exception(
- exception=exception
- )
-
- def bind(self, configurator: Configurator):
- configurator.add_view(
- self.notfound_view,
- renderer='json',
- context=HTTPNotFound,
- )
- configurator.add_view(
- self.exception_view,
- renderer='json',
- context=Exception,
- )
|