Revise parse_exception in the client side

Use jsonutils when the response is JSON format,
if not parse it by hand.

Change-Id: I2318b970b443888faa34431c284e3f85b7d4d266
This commit is contained in:
Haiwei Xu
2015-08-04 14:56:08 +09:00
parent 27c244d5b4
commit 1706db22ce

View File

@@ -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