From 1706db22ce0830ec56d6fb3d53bd595b609bccad Mon Sep 17 00:00:00 2001 From: Haiwei Xu Date: Tue, 4 Aug 2015 14:56:08 +0900 Subject: [PATCH] Revise parse_exception in the client side Use jsonutils when the response is JSON format, if not parse it by hand. Change-Id: I2318b970b443888faa34431c284e3f85b7d4d266 --- senlinclient/common/exc.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/senlinclient/common/exc.py b/senlinclient/common/exc.py index bde6a269..1ddaa0c0 100644 --- a/senlinclient/common/exc.py +++ b/senlinclient/common/exc.py @@ -231,12 +231,16 @@ def parse_exception(exc): :param details: details of the exception. ''' if isinstance(exc, sdkexc.HttpException): - record = { - 'error': { - 'code': exc.status_code, - 'message': exc.details, + try: + record = jsonutils.loads(exc.details) + except Exception: + # If the exc.details is not in JSON format + record = { + 'error': { + 'code': exc.status_code, + 'message': exc.details, + } } - } elif isinstance(exc, reqexc.RequestException): # Exceptions that are not captured by SDK code = exc.message[1].errno