|
@@ -1,71 +0,0 @@
|
1
|
|
-# coding=utf-8
|
2
|
|
-from pyramid.httpexceptions import HTTPNotFound
|
3
|
|
-
|
4
|
|
-from tracim import TracimRequest
|
5
|
|
-from tracim.extensions import hapic
|
6
|
|
-from tracim.views.controllers import Controller
|
7
|
|
-from tracim.views.errors import ErrorSchema
|
8
|
|
-from pyramid.config import Configurator
|
9
|
|
-
|
10
|
|
-
|
11
|
|
-class DefaultController(Controller):
|
12
|
|
-
|
13
|
|
- def notfound_view(
|
14
|
|
- self,
|
15
|
|
- exception: HTTPNotFound,
|
16
|
|
- request: TracimRequest
|
17
|
|
- ):
|
18
|
|
- """
|
19
|
|
- Catch Not Found Exception
|
20
|
|
- :param exception: Exception Object
|
21
|
|
- :param request: current Request
|
22
|
|
- :return: 500 Internal Server Error with same format as others errors
|
23
|
|
- """
|
24
|
|
- request.response.status = 404
|
25
|
|
- return hapic.context.get_default_error_builder().build_from_exception(
|
26
|
|
- exception=exception
|
27
|
|
- )
|
28
|
|
-
|
29
|
|
- def exception_view(
|
30
|
|
- self,
|
31
|
|
- exception: Exception,
|
32
|
|
- request: TracimRequest
|
33
|
|
- ):
|
34
|
|
- """
|
35
|
|
- Catch all exceptions not handled in view
|
36
|
|
- :param exception: Exception Object
|
37
|
|
- :param request: current Request
|
38
|
|
- :return: 500 Internal Server Error with same format as others errors
|
39
|
|
- """
|
40
|
|
- request.response.status = 500
|
41
|
|
- return hapic.context.get_default_error_builder().build_from_exception(
|
42
|
|
- exception=exception
|
43
|
|
- )
|
44
|
|
-
|
45
|
|
- def swagger_doc(self, request: TracimRequest):
|
46
|
|
- return hapic.generate_doc(
|
47
|
|
- title='Tracim v2 API',
|
48
|
|
- description='API of Tracim v2',
|
49
|
|
- )
|
50
|
|
-
|
51
|
|
- def bind(self, configurator: Configurator):
|
52
|
|
- configurator.add_view(
|
53
|
|
- self.notfound_view,
|
54
|
|
- renderer='json',
|
55
|
|
- context=HTTPNotFound,
|
56
|
|
- )
|
57
|
|
- configurator.add_view(
|
58
|
|
- self.exception_view,
|
59
|
|
- renderer='json',
|
60
|
|
- context=Exception,
|
61
|
|
- )
|
62
|
|
- configurator.add_route(
|
63
|
|
- 'swagger_doc',
|
64
|
|
- '/swagger_doc',
|
65
|
|
- request_method='GET',
|
66
|
|
- )
|
67
|
|
- configurator.add_view(
|
68
|
|
- self.swagger_doc,
|
69
|
|
- route_name='swagger_doc',
|
70
|
|
- renderer='json',
|
71
|
|
- )
|