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._