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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user