From 9617c7457c8d2914e012919df12674e8f9d50ad4 Mon Sep 17 00:00:00 2001 From: Haiwei Xu Date: Fri, 27 Nov 2015 17:09:19 +0900 Subject: [PATCH] Fix parse_exception to handle exception from keystoneauth1 Keystoneauth1 is used by OpenStackSDK, but OpenStackSDk does not handel the exceptions, senlinclient need to make the exception more readable. Change-Id: I17d900af88d4e668b2aabe37ca3f9d0b53e05af3 Closes-bug: #1520464 --- senlinclient/common/exc.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/senlinclient/common/exc.py b/senlinclient/common/exc.py index 1ddaa0c0..3102d3c0 100644 --- a/senlinclient/common/exc.py +++ b/senlinclient/common/exc.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from keystoneauth1.exceptions import base as kaexc from openstack import exceptions as sdkexc from oslo_serialization import jsonutils @@ -243,16 +244,23 @@ def parse_exception(exc): } elif isinstance(exc, reqexc.RequestException): # Exceptions that are not captured by SDK - code = exc.message[1].errno record = { 'error': { - 'code': code, + 'code': exc.message[1].errno, 'message': exc.message[0], } } elif isinstance(exc, six.string_types): record = jsonutils.loads(exc) + # some exception from keystoneauth1 is not shaped by SDK + elif isinstance(exc, kaexc.ClientException): + record = { + 'error': { + 'code': exc.http_status, + 'message': exc.message + } + } else: print(_('Unknown exception: %s') % exc) return