Create a handler for uncaught 404 errors

Change-Id: I31d80c45fa061872bb0127bb0cf90c8c1d6d79ed
Closes-Bug: #1474894
This commit is contained in:
Dmitry Tantsur 2015-07-16 14:29:35 +02:00
parent 4ed82f9029
commit 4dd5ac1eb3
2 changed files with 21 additions and 0 deletions

View File

@ -99,6 +99,11 @@ def api_introspection(uuid):
error=node_info.error or None)
@app.errorhandler(404)
def handle_404(error):
return error_response(error, code=404)
def periodic_update(period): # pragma: no cover
while True:
LOG.debug('Running periodic update of filters')

View File

@ -136,6 +136,22 @@ class TestApi(test_base.BaseTest):
self.assertEqual({'finished': True, 'error': 'boom'},
json.loads(res.data.decode('utf-8')))
@mock.patch.object(node_cache, 'get_node', autospec=True)
def test_404_expected(self, get_mock):
get_mock.side_effect = iter([utils.Error('boom', code=404)])
res = self.app.get('/v1/introspection/%s' % self.uuid)
self.assertEqual(404, res.status_code)
self.assertEqual(
'boom',
json.loads(res.data.decode('utf-8'))['error']['message'])
def test_404_unexpected(self):
res = self.app.get('/v42')
self.assertEqual(404, res.status_code)
self.assertIn(
'not found',
json.loads(res.data.decode('utf-8'))['error']['message'].lower())
class TestPlugins(unittest.TestCase):
@mock.patch.object(example_plugin.ExampleProcessingHook,