From 287e721f83dfd693c1af634c969a552eada45b2b Mon Sep 17 00:00:00 2001 From: Eli Qiao Date: Thu, 23 Feb 2017 10:56:54 +0800 Subject: [PATCH] Improve error message parsing Some improvments and cleanup. Related-Bug: #1634428 Change-Id: Ibca614084439222dcf1d5ab83ccc0aa4351b5f2d --- zunclient/common/httpclient.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/zunclient/common/httpclient.py b/zunclient/common/httpclient.py index 12ec934d..25a6c3dc 100644 --- a/zunclient/common/httpclient.py +++ b/zunclient/common/httpclient.py @@ -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 {}