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,6 +34,7 @@ class BottleContext(BaseContext):
34 34
         default_error_builder: ErrorBuilderInterface=None,
35 35
     ):
36 36
         self._handled_exception_and_http_codes = []  # type: typing.List[typing.Tuple[typing.Type[Exception], int]]  # nopep8
37
+        self._exceptions_handler_installed = False
37 38
         self.app = app
38 39
         self.default_error_builder = \
39 40
             default_error_builder or DefaultErrorBuilder()  # FDV
@@ -141,9 +142,20 @@ class BottleContext(BaseContext):
141 142
         exception_class: typing.Type[Exception],
142 143
         http_code: int,
143 144
     ) -> None:
145
+        if not self._exceptions_handler_installed:
146
+            self._install_exceptions_handler()
147
+
144 148
         self._handled_exception_and_http_codes.append(
145 149
             (exception_class, http_code),
146 150
         )
147 151
 
148 152
     def _install_exceptions_handler(self) -> None:
149 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