From f0fa95de32922658e9277a6e8ac15ad55efb1a40 Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Thu, 4 Dec 2014 13:17:43 -0500 Subject: [PATCH] Update oslo-incubator apiclient.exceptions Changes - * deprecate apiclient package * Handle different format of api exception * Split cliutils * Remove code that moved to oslo.i18n Change-Id: Iba23b2153b9f7be6ea6efe7ff189080a96c45168 --- .../openstack/common/apiclient/exceptions.py | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/saharaclient/openstack/common/apiclient/exceptions.py b/saharaclient/openstack/common/apiclient/exceptions.py index 9ef65075..6e9c9763 100644 --- a/saharaclient/openstack/common/apiclient/exceptions.py +++ b/saharaclient/openstack/common/apiclient/exceptions.py @@ -20,12 +20,25 @@ Exception definitions. """ +######################################################################## +# +# THIS MODULE IS DEPRECATED +# +# Please refer to +# https://etherpad.openstack.org/p/kilo-saharaclient-library-proposals for +# the discussion leading to this deprecation. +# +# We recommend checking out the python-openstacksdk project +# (https://launchpad.net/python-openstacksdk) instead. +# +######################################################################## + import inspect import sys import six -from saharaclient.openstack.common.gettextutils import _ +from saharaclient.openstack.common._i18n import _ class ClientException(Exception): @@ -34,14 +47,6 @@ class ClientException(Exception): pass -class MissingArgs(ClientException): - """Supplied arguments are not sufficient for calling a function.""" - def __init__(self, missing): - self.missing = missing - msg = _("Missing arguments: %s") % ", ".join(missing) - super(MissingArgs, self).__init__(msg) - - class ValidationError(ClientException): """Error in validation on API client side.""" pass @@ -447,10 +452,13 @@ def from_response(response, method, url): except ValueError: pass else: - if isinstance(body, dict) and isinstance(body.get("error"), dict): - error = body["error"] - kwargs["message"] = error.get("message") - kwargs["details"] = error.get("details") + if isinstance(body, dict): + error = body.get(list(body)[0]) + if isinstance(error, dict): + kwargs["message"] = (error.get("message") or + error.get("faultstring")) + kwargs["details"] = (error.get("details") or + six.text_type(body)) elif content_type.startswith("text/"): kwargs["details"] = response.text