diff --git a/src/pybind/mgr/dashboard_v2/module.py b/src/pybind/mgr/dashboard_v2/module.py index 8a469f7ebc2..acb5d0c282d 100644 --- a/src/pybind/mgr/dashboard_v2/module.py +++ b/src/pybind/mgr/dashboard_v2/module.py @@ -11,7 +11,7 @@ import cherrypy from mgr_module import MgrModule from .controllers.auth import Auth -from .tools import load_controllers +from .tools import load_controllers, json_error_page # cherrypy likes to sys.exit on error. don't let it take us down too! @@ -54,7 +54,8 @@ class Module(MgrModule): cherrypy.config.update({ 'server.socket_host': server_addr, 'server.socket_port': int(server_port), - 'engine.autoreload.on': False + 'engine.autoreload.on': False, + 'error_page.default': json_error_page }) cherrypy.tools.authenticate = cherrypy.Tool('before_handler', Auth.check_auth) diff --git a/src/pybind/mgr/dashboard_v2/tools.py b/src/pybind/mgr/dashboard_v2/tools.py index 2f42e24e766..ee3e276e0bb 100644 --- a/src/pybind/mgr/dashboard_v2/tools.py +++ b/src/pybind/mgr/dashboard_v2/tools.py @@ -69,7 +69,8 @@ def load_controllers(mgrmodule): return controllers -def _json_error_page(status, message, traceback, version): +def json_error_page(status, message, traceback, version): + cherrypy.response.headers['Content-Type'] = 'application/json' return json.dumps(dict(status=status, detail=message, traceback=traceback, version=version)) @@ -104,7 +105,7 @@ class BaseController(six.with_metaclass(BaseControllerMeta, object)): _mgr_module = None _cp_config_default = { - 'request.error_page': {'default': _json_error_page}, + 'request.error_page': {'default': json_error_page}, } @property @@ -194,7 +195,7 @@ class RESTController(BaseController): @cherrypy.expose def default(self, *vpath, **params): cherrypy.config.update({ - 'error_page.default': _json_error_page}) + 'error_page.default': json_error_page}) obj_key, detail_route_name = self.split_vpath(vpath) method, status_code = self._get_method(obj_key, detail_route_name)