summaryrefslogtreecommitdiff
path: root/neutronclient/v2_0
diff options
context:
space:
mode:
authorAkihiro Motoki <motoki@da.jp.nec.com>2014-03-03 00:52:49 +0900
committerAkihiro Motoki <motoki@da.jp.nec.com>2014-03-03 02:04:34 +0900
commitabfc6b6ae9647a3ca1a323caa07a9d370233f03c (patch)
treef0fc0f0cf14e71dad6969f50b4886c4e895d1ded /neutronclient/v2_0
parentfba38c6b27506ceaa175e16459b0f07918ae75c7 (diff)
downloadpython-neutronclient-abfc6b6ae9647a3ca1a323caa07a9d370233f03c.tar.gz
Print human friendly string as an error message
This commit also removes a blank line displayed when error_dict['detail'] is empty. When 403 is returned, Forbidden exception is raised from HTTPClient (neutronclient/client.py). There is no reason this exception is raised by it. By this commit v2_0.client now handles 403 response to show human friendly message by parsing Neutron 2.0 -specific error format. Change-Id: Iefbd7db094267fe3799ebf4713e142e62c63174c Closes-Bug: #1246271
Diffstat (limited to 'neutronclient/v2_0')
-rw-r--r--neutronclient/v2_0/client.py45
1 files changed, 21 insertions, 24 deletions
diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py
index 99ff6e2..64736a7 100644
--- a/neutronclient/v2_0/client.py
+++ b/neutronclient/v2_0/client.py
@@ -30,6 +30,18 @@ from neutronclient.common import utils
_logger = logging.getLogger(__name__)
+NEUTRON_ERRORS = {
+ 'NetworkNotFound': exceptions.NetworkNotFoundClient,
+ 'NetworkInUse': exceptions.NetworkInUseClient,
+ 'PortNotFound': exceptions.PortNotFoundClient,
+ 'RequestedStateInvalid': exceptions.StateInvalidClient,
+ 'PortInUse': exceptions.PortInUseClient,
+ 'IpAddressInUse': exceptions.IpAddressInUseClient,
+ 'AlreadyAttached': exceptions.AlreadyAttachedClient,
+ 'IpAddressGenerationFailure': exceptions.IpAddressGenerationFailureClient,
+ 'ExternalIpAddressExhausted': exceptions.ExternalIpAddressExhaustedClient,
+}
+
def exception_handler_v20(status_code, error_content):
"""Exception handler for API v2.0 client
@@ -41,20 +53,6 @@ def exception_handler_v20(status_code, error_content):
:param status_code: HTTP error status code
:param error_content: deserialized body of error response
"""
-
- neutron_errors = {
- 'NetworkNotFound': exceptions.NetworkNotFoundClient,
- 'NetworkInUse': exceptions.NetworkInUseClient,
- 'PortNotFound': exceptions.PortNotFoundClient,
- 'RequestedStateInvalid': exceptions.StateInvalidClient,
- 'PortInUse': exceptions.PortInUseClient,
- 'IpAddressInUse': exceptions.IpAddressInUseClient,
- 'AlreadyAttached': exceptions.AlreadyAttachedClient,
- 'IpAddressGenerationFailure':
- exceptions.IpAddressGenerationFailureClient,
- 'ExternalIpAddressExhausted':
- exceptions.ExternalIpAddressExhaustedClient, }
-
error_dict = None
if isinstance(error_content, dict):
error_dict = error_content.get('NeutronError')
@@ -65,27 +63,26 @@ def exception_handler_v20(status_code, error_content):
# a 'message' and 'type' keys?
try:
error_type = error_dict['type']
- error_message = (error_dict['message'] + "\n" +
- error_dict['detail'])
+ error_message = error_dict['message']
+ if error_dict['detail']:
+ error_message += "\n" + error_dict['detail']
except Exception:
bad_neutron_error_flag = True
if not bad_neutron_error_flag:
- ex = None
try:
# raise the appropriate error!
- ex = neutron_errors[error_type](message=error_message,
- status_code=status_code)
- except Exception:
- pass
- if ex:
- raise ex
+ raise NEUTRON_ERRORS[error_type](message=error_message,
+ status_code=status_code)
+ except KeyError:
+ raise exceptions.NeutronClientException(
+ status_code=status_code, message=error_message)
else:
raise exceptions.NeutronClientException(status_code=status_code,
message=error_dict)
else:
message = None
if isinstance(error_content, dict):
- message = error_content.get('message', None)
+ message = error_content.get('message')
if message:
raise exceptions.NeutronClientException(status_code=status_code,
message=message)