Browse Source

fix BottleContext

Bastien Sevajol 6 years ago
parent
commit
899e928c3a
1 changed files with 12 additions and 0 deletions
  1. 12 0
      hapic/ext/bottle/context.py

+ 12 - 0
hapic/ext/bottle/context.py View File

34
         default_error_builder: ErrorBuilderInterface=None,
34
         default_error_builder: ErrorBuilderInterface=None,
35
     ):
35
     ):
36
         self._handled_exception_and_http_codes = []  # type: typing.List[typing.Tuple[typing.Type[Exception], int]]  # nopep8
36
         self._handled_exception_and_http_codes = []  # type: typing.List[typing.Tuple[typing.Type[Exception], int]]  # nopep8
37
+        self._exceptions_handler_installed = False
37
         self.app = app
38
         self.app = app
38
         self.default_error_builder = \
39
         self.default_error_builder = \
39
             default_error_builder or DefaultErrorBuilder()  # FDV
40
             default_error_builder or DefaultErrorBuilder()  # FDV
141
         exception_class: typing.Type[Exception],
142
         exception_class: typing.Type[Exception],
142
         http_code: int,
143
         http_code: int,
143
     ) -> None:
144
     ) -> None:
145
+        if not self._exceptions_handler_installed:
146
+            self._install_exceptions_handler()
147
+
144
         self._handled_exception_and_http_codes.append(
148
         self._handled_exception_and_http_codes.append(
145
             (exception_class, http_code),
149
             (exception_class, http_code),
146
         )
150
         )
147
 
151
 
148
     def _install_exceptions_handler(self) -> None:
152
     def _install_exceptions_handler(self) -> None:
149
         self.app.install(self.handle_exceptions_decorator_builder)
153
         self.app.install(self.handle_exceptions_decorator_builder)
154
+
155
+    def _get_handled_exception_class_and_http_codes(
156
+        self,
157
+    ) -> typing.List[typing.Tuple[typing.Type[Exception], int]]:
158
+        """
159
+        See hapic.context.BaseContext#_get_handled_exception_class_and_http_codes  # nopep8
160
+        """
161
+        return self._handled_exception_and_http_codes