summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Betts <sam@code-smash.net>2018-05-11 12:27:43 +0100
committerSam Betts <sam@code-smash.net>2018-05-14 15:35:18 +0100
commitf988eb6d89efd772af77ed0bbc41fde9764d640a (patch)
tree7601b9213679664fcb69bc8c5831811e451f87ad
parentc6596e9f41ad3de1b3283679e41f9662eeb02864 (diff)
downloadpython-ironicclient-f988eb6d89efd772af77ed0bbc41fde9764d640a.tar.gz
Stop double json decoding API error messages
This patch adds support for the fixed error messages that aren't double JSON encoded. Change-Id: Ib39f65c89e3e96efddd9fa3b648145ae3d6159d3 Story: #1662228 Task: #19644
-rw-r--r--ironicclient/common/http.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/ironicclient/common/http.py b/ironicclient/common/http.py
index 1d293a2..db3c06a 100644
--- a/ironicclient/common/http.py
+++ b/ironicclient/common/http.py
@@ -69,16 +69,24 @@ def _trim_endpoint_api_version(url):
def _extract_error_json(body):
"""Return error_message from the HTTP response body."""
- error_json = {}
try:
body_json = jsonutils.loads(body)
- if 'error_message' in body_json:
- raw_msg = body_json['error_message']
- error_json = jsonutils.loads(raw_msg)
except ValueError:
- pass
+ return {}
- return error_json
+ if 'error_message' not in body_json:
+ return {}
+
+ try:
+ error_json = jsonutils.loads(body_json['error_message'])
+ except ValueError:
+ return body_json
+
+ err_msg = (error_json.get('faultstring') or error_json.get('description'))
+ if err_msg:
+ body_json['error_message'] = err_msg
+
+ return body_json
def get_server(endpoint):
@@ -433,12 +441,8 @@ class HTTPClient(VersionNegotiationMixin):
if resp.status_code >= http_client.BAD_REQUEST:
error_json = _extract_error_json(body_str)
- # NOTE(vdrok): exceptions from ironic controllers' _lookup methods
- # are constructed directly by pecan instead of wsme, and contain
- # only description field
raise exc.from_response(
- resp, (error_json.get('faultstring') or
- error_json.get('description')),
+ resp, error_json.get('error_message'),
error_json.get('debuginfo'), method, url)
elif resp.status_code in (http_client.MOVED_PERMANENTLY,
http_client.FOUND,
@@ -615,11 +619,7 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter):
return self._http_request(url, method, **kwargs)
if resp.status_code >= http_client.BAD_REQUEST:
error_json = _extract_error_json(resp.content)
- # NOTE(vdrok): exceptions from ironic controllers' _lookup methods
- # are constructed directly by pecan instead of wsme, and contain
- # only description field
- raise exc.from_response(resp, (error_json.get('faultstring') or
- error_json.get('description')),
+ raise exc.from_response(resp, error_json.get('error_message'),
error_json.get('debuginfo'), method, url)
elif resp.status_code in (http_client.MOVED_PERMANENTLY,
http_client.FOUND, http_client.USE_PROXY):