Fix uncaught NotFound exceptions
There are a couple of places in the code where we were not catching NotFound exceptions which resulted in getting the exception logged incorrectly in the logs and the error message being returned by the WSGI layer being slightly off. Cases where this was happening are volume encryption metadata and volume transfer. From the user perspective the error was very similar to what it was expected, but it was preceeded by the name of the Cinder exception (ex: VolumeNotFound: ). This patch catches all NotFound exception at the WSGI level and properly converts them, that way we prevent the exception to propagate to the middleware fault level and generate a log exception and return slightly different error. Change-Id: I8971afedd68854d2840ab551b420ca083e8ee0d6
This commit is contained in:
@@ -595,7 +595,7 @@ class ResourceExceptionHandler(object):
|
||||
raise Fault(webob.exc.HTTPForbidden(explanation=msg))
|
||||
elif isinstance(ex_value, exception.VersionNotFoundForAPIMethod):
|
||||
raise
|
||||
elif isinstance(ex_value, exception.Invalid):
|
||||
elif isinstance(ex_value, (exception.Invalid, exception.NotFound)):
|
||||
raise Fault(exception.ConvertedException(
|
||||
code=ex_value.code, explanation=six.text_type(ex_value)))
|
||||
elif isinstance(ex_value, TypeError):
|
||||
|
||||
@@ -112,8 +112,7 @@ class VolumeEncryptionMetadataTest(test.TestCase):
|
||||
|
||||
res_dict = jsonutils.loads(res.body)
|
||||
expected = {'itemNotFound': {'code': 404,
|
||||
'message': 'VolumeNotFound: Volume '
|
||||
'%s could not be found.'
|
||||
'message': 'Volume %s could not be found.'
|
||||
% bad_volume_id}}
|
||||
self.assertEqual(expected, res_dict)
|
||||
|
||||
@@ -168,8 +167,7 @@ class VolumeEncryptionMetadataTest(test.TestCase):
|
||||
|
||||
res_dict = jsonutils.loads(res.body)
|
||||
expected = {'itemNotFound': {'code': 404,
|
||||
'message': 'VolumeNotFound: Volume '
|
||||
'%s could not be found.'
|
||||
'message': 'Volume %s could not be found.'
|
||||
% bad_volume_id}}
|
||||
self.assertEqual(expected, res_dict)
|
||||
|
||||
|
||||
@@ -430,7 +430,7 @@ class VolumeTransferAPITestCase(test.TestCase):
|
||||
|
||||
self.assertEqual(404, res.status_int)
|
||||
self.assertEqual(404, res_dict['itemNotFound']['code'])
|
||||
self.assertEqual('TransferNotFound: Transfer %s could not be found.' %
|
||||
self.assertEqual('Transfer %s could not be found.' %
|
||||
fake.WILL_NOT_BE_FOUND_ID,
|
||||
res_dict['itemNotFound']['message'])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user