Improve error message parsing

Some improvments and cleanup.

Related-Bug: #1634428
Change-Id: Ibca614084439222dcf1d5ab83ccc0aa4351b5f2d
This commit is contained in:
Eli Qiao 2017-02-23 10:56:54 +08:00 committed by Hongbin Lu
parent f51148d284
commit 287e721f83

View File

@ -44,11 +44,17 @@ def _extract_error_json(body):
if 'error_message' in body_json:
raw_msg = body_json['error_message']
error_json = json.loads(raw_msg)
elif 'error' in body_json:
error_body = body_json['error']
error_json = {'faultstring': error_body['title'],
'debuginfo': error_body['message']}
else:
error_body = body_json['errors'][0]
raw_msg = error_body['title']
error_json = {'faultstring': error_body['title'],
'debuginfo': error_body['detail']}
error_json = {'faultstring': error_body['title']}
if 'detail' in error_body:
error_json['debuginfo'] = error_body['detail']
elif 'description' in error_body:
error_json['debuginfo'] = error_body['description']
except ValueError:
return {}