From 03b0e72a31d32c2919cd98a047bdd23f861cfbcf Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 16 Jan 2013 18:55:58 +0100 Subject: [PATCH] ReST API: Clean up exception-handling cruft 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 --- heat/api/openstack/v1/stacks.py | 6 +++--- heat/api/openstack/v1/util.py | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/heat/api/openstack/v1/stacks.py b/heat/api/openstack/v1/stacks.py index 3152916c..96d4e8a6 100644 --- a/heat/api/openstack/v1/stacks.py +++ b/heat/api/openstack/v1/stacks.py @@ -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']) diff --git a/heat/api/openstack/v1/util.py b/heat/api/openstack/v1/util.py index 708a2829..6afea9d3 100644 --- a/heat/api/openstack/v1/util.py +++ b/heat/api/openstack/v1/util.py @@ -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, -- 2.45.2