Fix HTTP response code on errors

Redfish requires returning HTTP codes in the range of 400-500
on failures. Such responses must be accompanied by error details
in form of a JSON document.

This patch makes general error handler returning HTTP code 500
instead of 200.

Change-Id: I89de76bc5e7d35f5130935af9f6ddd67e61d8b49
This commit is contained in:
Ilya Etingof 2018-11-15 10:26:11 +01:00
parent c09ce2ce75
commit dc2e5dc5d7
2 changed files with 7 additions and 1 deletions

View File

@ -82,7 +82,7 @@ def returns_json(decorated_func):
@app.errorhandler(Exception)
@returns_json
def all_exception_handler(message):
return flask.render_template('error.json', message=message)
return flask.render_template('error.json', message=message), 500
@app.route('/redfish/v1/')

View File

@ -27,6 +27,12 @@ class EmulatorTestCase(base.BaseTestCase):
super(EmulatorTestCase, self).setUp()
def test_error(self, driver_mock):
driver_mock.get_power_state.side_effect = Exception('Fish is dead')
response = self.app.get('/redfish/v1/Systems/xxxx-yyyy-zzzz')
self.assertEqual('500 INTERNAL SERVER ERROR', response.status)
def test_bios(self, driver_mock):
driver_mock.get_bios.return_value = {"attribute 1": "value 1",
"attribute 2": "value 2"}