mgr/dashboard_v2: Fix content type (body) of error page

Signed-off-by: Patrick Nawracay <pnawracay@suse.com>
This commit is contained in:
Patrick Nawracay 2018-01-26 14:41:55 +01:00 committed by Ricardo Dias
parent c866b73377
commit f4624947d6
No known key found for this signature in database
GPG Key ID: 74390C579BD37B68
2 changed files with 7 additions and 5 deletions

View File

@ -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)

View File

@ -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)