diff --git a/server/src/server.py b/server/src/server.py index 3dfd7f2fa..3abf73f43 100755 --- a/server/src/server.py +++ b/server/src/server.py @@ -37,7 +37,12 @@ class PermissionError(Exception): - pass + def json(self, json_dic): + json_dic['exception'] = 'permissionError' + +class ConfigurationError(Exception): + def json(self, json_dic): + json_dic['exception'] = 'configurationError' # TODO: Possibly check configurations too @@ -59,10 +64,6 @@ def _permission_check(): raise PermissionError -class ConfigurationError(Exception): - pass - - # Error message template functions def _miss_var_msg(var): return ('Missing variable "%s" in %s, make sure that you have ' @@ -258,7 +259,7 @@ def _server_crash(cookie_hdrs, e): print >> stderr, stack_trace json_dic = { - 'exception': True, + 'exception': 'serverCrash', } return (cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json(json_dic)))) @@ -293,15 +294,17 @@ def serve(params, client_ip, client_hostname, cookie_data): # can thus manipulate each other's global variables with CONFIG_CHECK_LOCK: _config_check() - except ConfigurationError: - return cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json({}))) + except ConfigurationError, e: + exception_json = e.json() + return cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json(exception_json))) # We can now safely read the config from config import DEBUG try: _permission_check() - except PermissionError: - return cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json({}))) + except PermissionError, e: + exception_json = e.json() + return cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json(exception_json))) try: # Safe region, can throw any exception, has verified installation