Parcourir la source

Enabled middleware for wrapping all exceptions

closes: https://github.com/CloudVE/cloudbridge/issues/84
Nuwan Goonasekera il y a 7 ans
Parent
commit
326dfe2449
1 fichiers modifiés avec 9 ajouts et 0 suppressions
  1. 9 0
      cloudbridge/cloud/base/provider.py

+ 9 - 0
cloudbridge/cloud/base/provider.py

@@ -11,6 +11,7 @@ except ImportError:  # Python 2
 import six
 
 from ..base.events import SimpleEventDispatcher
+from ..base.middleware import ExceptionWrappingMiddleware
 from ..base.middleware import SimpleMiddlewareManager
 from ..interfaces import CloudProvider
 from ..interfaces.exceptions import ProviderConnectionException
@@ -88,6 +89,7 @@ class BaseCloudProvider(CloudProvider):
         self._config_parser.read(CloudBridgeConfigLocations)
         self._events = SimpleEventDispatcher()
         self._middleware = SimpleMiddlewareManager(self._events)
+        self.add_required_middleware()
 
     @property
     def config(self):
@@ -105,6 +107,13 @@ class BaseCloudProvider(CloudProvider):
     def middleware(self):
         return self._middleware
 
+    def add_required_middleware(self):
+        """
+        Adds common middleware that is essential for cloudbridge to function.
+        Any other extra middleware can be added through the provider factory.
+        """
+        self.middleware.add(ExceptionWrappingMiddleware())
+
     def authenticate(self):
         """
         A basic implementation which simply runs a low impact command to