]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
ReST API: Clean up exception-handling cruft
authorZane Bitter <zbitter@redhat.com>
Wed, 16 Jan 2013 17:55:58 +0000 (18:55 +0100)
committerZane Bitter <zbitter@redhat.com>
Thu, 17 Jan 2013 10:47:47 +0000 (11:47 +0100)
Now that we have explicit exception types indicating when a resource is not
found we don't have to rely on knowing which call the error was from.

Change-Id: I54ebce7cb68e551852fd87d51b57b26536cde136
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/api/openstack/v1/stacks.py
heat/api/openstack/v1/util.py

index 3152916c1185a9b1ea1bb62c3fb0a82f9e131c69..96d4e8a67f280ebcb27bd9a08f8ee41b45fd36f6 100644 (file)
@@ -153,7 +153,7 @@ class StackController(object):
         try:
             stacks = self.engine.list_stacks(req.context)
         except rpc_common.RemoteError as ex:
-            return util.remote_error(ex, True)
+            return util.remote_error(ex)
 
         summary_keys = (engine_api.STACK_ID,
                         engine_api.STACK_NAME,
@@ -181,7 +181,7 @@ class StackController(object):
                                               data.user_params(),
                                               data.args())
         except rpc_common.RemoteError as ex:
-            return util.remote_error(ex, True)
+            return util.remote_error(ex)
 
         if 'Description' in result:
             raise exc.HTTPBadRequest(explanation=result['Description'])
@@ -296,7 +296,7 @@ class StackController(object):
             result = self.engine.validate_template(req.context,
                                                    data.template())
         except rpc_common.RemoteError as ex:
-            return util.remote_error(ex, True)
+            return util.remote_error(ex)
 
         if 'Error' in result:
             raise exc.HTTPBadRequest(explanation=result['Error'])
index 708a28291ab14bb4a2c0c27972b7befba65c5774..6afea9d3ad2dfbac68a9b2351212d48ec7d8d907 100644 (file)
@@ -80,17 +80,16 @@ def make_link(req, identity, relationship='self'):
     return {'href': make_url(req, identity), 'rel': relationship}
 
 
-def remote_error(ex, force_exists=False):
+def remote_error(ex):
     """
     Map rpc_common.RemoteError exceptions returned by the engine
     to webob exceptions which can be used to return
     properly formatted error responses.
     """
 
-    client_error = exc.HTTPBadRequest if force_exists else exc.HTTPNotFound
     error_map = {
-        'AttributeError': client_error,
-        'ValueError': client_error,
+        'AttributeError': exc.HTTPBadRequest,
+        'ValueError': exc.HTTPBadRequest,
         'StackNotFound': exc.HTTPNotFound,
         'ResourceNotFound': exc.HTTPNotFound,
         'ResourceNotAvailable': exc.HTTPNotFound,