Fix SDK exception parsing

There are cases we are not parsing the SDK exceptions properly. This
patch is an attempt to fix this problem.

Change-Id: I9ba7756587e87b74b66d8b871e16bcf4700603e9
This commit is contained in:
tengqm
2016-02-27 01:10:43 -05:00
parent 5f49c45b84
commit ebcaa2aabb

View File

@@ -233,16 +233,37 @@ def parse_exception(exc):
:param details: details of the exception.
"""
if isinstance(exc, sdkexc.HttpException):
try:
record = jsonutils.loads(exc.details)
except Exception:
# If the exc.details is not in JSON format
record = {
'error': {
'code': exc.http_status,
'message': exc,
if exc.details is None:
data = exc.response.json()
code = data.get('code', None)
message = data.get('message', None)
error = data.get('error', None)
if error:
record = {
'error': {
'code': exc.http_status,
'message': message or exc.message
}
}
else:
info = data.values()[0]
record = {
'error': {
'code': info.get('code', code),
'message': info.get('message', message)
}
}
else:
try:
record = jsonutils.loads(exc.details)
except Exception:
# If the exc.details is not in JSON format
record = {
'error': {
'code': exc.http_status,
'message': exc,
}
}
}
elif isinstance(exc, reqexc.RequestException):
# Exceptions that are not captured by SDK
record = {