diff --git a/vmware_nsx/common/exceptions.py b/vmware_nsx/common/exceptions.py index 85ecea48d0..be39f76548 100644 --- a/vmware_nsx/common/exceptions.py +++ b/vmware_nsx/common/exceptions.py @@ -127,7 +127,13 @@ class NoRouterAvailable(n_exc.ResourceExhausted): class ManagerError(NsxPluginException): message = _("Unexpected error from backend manager (%(manager)s) " - "for %(operation)s") + "for %(operation)s %(details)s") + + def __init__(self, **kwargs): + kwargs['details'] = (': %s' % kwargs['details'] + if 'details' in kwargs + else '') + super(ManagerError, self).__init__(**kwargs) class ResourceNotFound(ManagerError): diff --git a/vmware_nsx/nsxlib/v3/client.py b/vmware_nsx/nsxlib/v3/client.py index caa122c2f8..adf22fd6a3 100644 --- a/vmware_nsx/nsxlib/v3/client.py +++ b/vmware_nsx/nsxlib/v3/client.py @@ -101,17 +101,23 @@ class RESTClient(object): def _validate_result(self, result, expected, operation): if result.status_code not in expected: + result_msg = result.json() if result.content else '' LOG.warning(_LW("The HTTP request returned error code " "%(result)d, whereas %(expected)s response " "codes were expected. Response body %(body)s"), {'result': result.status_code, 'expected': '/'.join([str(code) for code in expected]), - 'body': result.json() if result.content else ''}) + 'body': result_msg}) manager_error = ERRORS.get( result.status_code, nsx_exc.ManagerError) - raise manager_error(manager=self._host_ip, operation=operation) + if type(result_msg) is dict: + result_msg = result_msg.get('error_message', result_msg) + raise manager_error( + manager=self._host_ip, + operation=operation, + details=result_msg) @classmethod def merge_headers(cls, *headers):