From e6e8d0f08c6f16a78d8686d411e08c8572a9ee23 Mon Sep 17 00:00:00 2001 From: Haiwei Xu Date: Fri, 4 Dec 2015 12:05:52 +0900 Subject: [PATCH] Specify keystoneauth1 exception more Currently all exceptions from keystoneauth1 are handled in the same way, but not all the exceptions have http_status property, so need to specify the exception types. Change-Id: I410f31544e0cdbd4e3d8f6470fcc8c7ee4c46ff2 Closes-bug: #1522664 --- senlinclient/common/exc.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/senlinclient/common/exc.py b/senlinclient/common/exc.py index 3102d3c0..0ddb4782 100644 --- a/senlinclient/common/exc.py +++ b/senlinclient/common/exc.py @@ -10,7 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. -from keystoneauth1.exceptions import base as kaexc +from keystoneauth1.exceptions import base as kae_base +from keystoneauth1.exceptions import http as kae_http from openstack import exceptions as sdkexc from oslo_serialization import jsonutils @@ -254,13 +255,22 @@ def parse_exception(exc): elif isinstance(exc, six.string_types): record = jsonutils.loads(exc) # some exception from keystoneauth1 is not shaped by SDK - elif isinstance(exc, kaexc.ClientException): + elif isinstance(exc, kae_http.HttpError): record = { 'error': { 'code': exc.http_status, 'message': exc.message } } + elif isinstance(exc, kae_base.ClientException): + record = { + 'error': { + # other exceptions from keystoneauth1 is an internal + # error to senlin, so set status code to 500 + 'code': 500, + 'message': exc.message + } + } else: print(_('Unknown exception: %s') % exc) return