NSXv: Fix backend error handling

Change-Id: I9aa0d56a6a393a02d4cac6bf8f769675d8262e67
This commit is contained in:
Roey Chen 2017-01-31 04:14:22 -08:00
parent d3ca979d0f
commit b881465244

View File

@ -108,7 +108,7 @@ class VcnsApiHelper(object):
try: try:
if self.format == 'xml': if self.format == 'xml':
error = et.fromstring(content).find('errorCode') error = et.fromstring(content).find('errorCode')
errcode = error and int(error.text) errcode = error is not None and int(error.text)
else: # json else: # json
error = jsonutils.loads(content) error = jsonutils.loads(content)
errcode = int(error.get('errorCode')) errcode = int(error.get('errorCode'))
@ -147,10 +147,10 @@ class VcnsApiHelper(object):
return response.headers, response.text return response.headers, response.text
nsx_errcode = self._get_nsx_errorcode(response.text) nsx_errcode = self._get_nsx_errorcode(response.text)
if status in self.errors: if nsx_errcode in self.nsx_errors:
cls = self.errors[status]
elif nsx_errcode in self.nsx_errors:
cls = self.nsx_errors[nsx_errcode] cls = self.nsx_errors[nsx_errcode]
elif status in self.errors:
cls = self.errors[status]
else: else:
cls = exceptions.VcnsApiException cls = exceptions.VcnsApiException
raise cls(uri=uri, status=status, raise cls(uri=uri, status=status,