From ee5c9ad03c9d301d01716e56710fe24a67f0f869 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Fri, 13 Apr 2018 10:12:12 +0200 Subject: [PATCH] mgr/dashboard: Modify RGW proxy response of errors to display a detailed message in the error notification. Signed-off-by: Volker Theile --- qa/tasks/mgr/dashboard/test_rgw.py | 15 ++++++------ src/pybind/mgr/dashboard/controllers/rgw.py | 26 +++++++++------------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_rgw.py b/qa/tasks/mgr/dashboard/test_rgw.py index 4e780fabfb37b..81eced2f6d082 100644 --- a/qa/tasks/mgr/dashboard/test_rgw.py +++ b/qa/tasks/mgr/dashboard/test_rgw.py @@ -43,8 +43,8 @@ class RgwProxyExceptionsTest(DashboardTestCase): @authenticate def test_no_credentials_exception(self): resp = self._get('/api/rgw/proxy/status') - self.assertStatus(401) - self.assertIn('message', resp) + self.assertStatus(500) + self.assertIn('detail', resp) class RgwProxyTest(DashboardTestCase): @@ -115,12 +115,13 @@ class RgwProxyTest(DashboardTestCase): self.assertStatus(200) self._delete('/api/rgw/proxy/user', params={'uid': 'teuth-test-user'}) - self.assertStatus(404) + self.assertStatus(500) resp = self._resp.json() - self.assertIn('Code', resp) - self.assertIn('HostId', resp) - self.assertIn('RequestId', resp) - self.assertEqual(resp['Code'], 'NoSuchUser') + self.assertIn('detail', resp) + self.assertIn('failed request with status code 404', resp['detail']) + self.assertIn('"Code":"NoSuchUser"', resp['detail']) + self.assertIn('"HostId"', resp['detail']) + self.assertIn('"RequestId"', resp['detail']) @authenticate def test_rgw_proxy(self): diff --git a/src/pybind/mgr/dashboard/controllers/rgw.py b/src/pybind/mgr/dashboard/controllers/rgw.py index d43e9e476b946..e7cdaa3939073 100644 --- a/src/pybind/mgr/dashboard/controllers/rgw.py +++ b/src/pybind/mgr/dashboard/controllers/rgw.py @@ -8,8 +8,6 @@ from . import ApiController, BaseController, RESTController, AuthRequired from .. import logger from ..services.ceph_service import CephService from ..services.rgw_client import RgwClient -from ..rest_client import RequestException -from ..exceptions import NoCredentialsException @ApiController('rgw') @@ -73,19 +71,17 @@ class RgwProxy(BaseController): try: rgw_client = RgwClient.admin_instance() - except NoCredentialsException as e: - cherrypy.response.headers['Content-Type'] = 'application/json' - cherrypy.response.status = 401 - return json.dumps({'message': str(e)}).encode('utf-8') - - method = cherrypy.request.method - data = None + method = cherrypy.request.method + data = None - if cherrypy.request.body.length: - data = cherrypy.request.body.read() + if cherrypy.request.body.length: + data = cherrypy.request.body.read() - try: return rgw_client.proxy(method, path, params, data) - except RequestException as e: - cherrypy.response.status = e.status_code - return e.content + except Exception as e: # pylint: disable=broad-except + # Always use status code 500 and NOT the status that may delivered + # by the exception. That's because we do not want to forward e.g. + # 401 or 404 that may trigger unwanted actions in the UI. + cherrypy.response.headers['Content-Type'] = 'application/json' + cherrypy.response.status = 500 + return json.dumps({'detail': str(e)}).encode('utf-8') -- 2.39.5