]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Prepare the groundwork for more exception types
authorZane Bitter <zbitter@redhat.com>
Thu, 17 Jan 2013 10:10:14 +0000 (11:10 +0100)
committerZane Bitter <zbitter@redhat.com>
Thu, 17 Jan 2013 10:47:47 +0000 (11:47 +0100)
We have been abusing AttributeError and ValueError rather than raising
exceptions that actually describe the problem. This opens the way for
changes that will allow us to handle a wide variety of specific exceptions.

Change-Id: I05c99601d4e877878195e658908fffa0e126f06c
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/api/aws/exception.py
heat/api/openstack/v1/util.py
heat/tests/test_engine_service.py

index 60712082cd79157f8fdea6377da04fdd3c0381d4..9dca5ec23b8bda39da0a58e91997e8228a9eb38f 100644 (file)
@@ -243,10 +243,13 @@ def map_remote_error(ex):
         to HeatAPIException subclasses which can be used to return
         properly formatted AWS error responses
         """
-        if ex.exc_type in ('AttributeError', 'ValueError'):
-            # Attribute/Value error, bad user data, ex.value should tell us why
+        inval_param_errors = (
+            'AttributeError',
+            'ValueError',
+        )
+
+        if ex.exc_type in inval_param_errors:
             return HeatInvalidParameterValueError(detail=ex.value)
         else:
             # Map everything else to internal server error for now
-            # FIXME : further investigation into engine errors required
             return HeatInternalFailureError(detail=ex.value)
index 3b358dfd01f0b800cb093cdfd414aeb8ffd1c39e..73eb8444d973740a1a7a1c608c34af5eafaa1184 100644 (file)
@@ -86,10 +86,13 @@ def remote_error(ex, force_exists=False):
     to webob exceptions which can be used to return
     properly formatted error responses.
     """
-    if ex.exc_type in ('AttributeError', 'ValueError'):
-        if force_exists:
-            raise exc.HTTPBadRequest(explanation=str(ex))
-        else:
-            raise exc.HTTPNotFound(explanation=str(ex))
 
-    raise exc.HTTPInternalServerError(explanation=str(ex))
+    client_error = exc.HTTPBadRequest if force_exists else exc.HTTPNotFound
+    error_map = {
+        'AttributeError': client_error,
+        'ValueError': client_error,
+    }
+
+    Exc = error_map.get(ex.exc_type, exc.HTTPInternalServerError)
+
+    raise Exc(explanation=str(ex))
index 5037aada3f370f98caaf69f30f271e1d925409cf..1c3b077db06772bcfd55177ed96f52a33e120f52 100644 (file)
@@ -20,6 +20,7 @@ import mox
 from nose.plugins.attrib import attr
 
 from heat.common import context
+from heat.common import exception
 from heat.tests.v1_1 import fakes
 import heat.engine.api as engine_api
 import heat.db as db_api