From 3403ae4de4134b70c00443b42afaa7470a56d2b5 Mon Sep 17 00:00:00 2001 From: Andrew Lazarev Date: Fri, 8 Aug 2014 15:52:22 -0700 Subject: [PATCH] Added hadling of non-json response from Sahara Added predicted behavior in case if Sahara responds with service exceptions. Client now can handle non-json responses. Change-Id: Ib3c47249eb58409b4c72c1beecd2403984c9e82e Closes-Bug: #1354556 --- saharaclient/api/base.py | 11 ++++++++++- tox.ini | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/saharaclient/api/base.py b/saharaclient/api/base.py index 24be2574..c2c9c368 100644 --- a/saharaclient/api/base.py +++ b/saharaclient/api/base.py @@ -18,6 +18,8 @@ import logging import six +from saharaclient.openstack.common.gettextutils import _ + LOG = logging.getLogger(__name__) @@ -130,7 +132,14 @@ class ResourceManager(object): return self.resource_class.resource_name + 's' def _raise_api_exception(self, resp): - error_data = get_json(resp) + try: + error_data = get_json(resp) + except Exception: + raise APIException( + error_code=resp.status_code, + error_message=_("Failed to parse response from Sahara. Check " + "if service catalog configured properly.")) + raise APIException(error_code=error_data.get("error_code"), error_name=error_data.get("error_name"), error_message=error_data.get("error_message")) diff --git a/tox.ini b/tox.ini index aae3630c..2bb11eaf 100644 --- a/tox.ini +++ b/tox.ini @@ -46,3 +46,5 @@ show-source = true builtins = _ exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools +[hacking] +import_exceptions = saharaclient.openstack.common.gettextutils._