From dd9c9a7c3cddf95a348225afe43588749494ee9b Mon Sep 17 00:00:00 2001 From: Nikita Konovalov Date: Thu, 5 Feb 2015 15:57:34 +0300 Subject: [PATCH] Improved exception handling The exception from response method behavior changed to match the fields that are returned from the API. This actually means changing oslo files which is not a recommended thing to do, but I see no other way to inject a custom error parsing to their code. Monkey-patching is worse option I think. Change-Id: I33b926b9541c3e16b256d7e7383fa65a89bb5642 --- .../openstack/common/apiclient/exceptions.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/storyboardclient/openstack/common/apiclient/exceptions.py b/storyboardclient/openstack/common/apiclient/exceptions.py index ba1fcca..d716d0e 100644 --- a/storyboardclient/openstack/common/apiclient/exceptions.py +++ b/storyboardclient/openstack/common/apiclient/exceptions.py @@ -458,12 +458,10 @@ def from_response(response, method, url): pass else: 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)) + kwargs["message"] = (body.get("message") or + body.get("faultstring")) + kwargs["details"] = (body.get("details") or + six.text_type(body)) elif content_type.startswith("text/"): kwargs["details"] = response.text