Commit e7d5c234 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Allow raising AjaxException on workspace.

parent f92bf5d5
......@@ -7,3 +7,30 @@ send = None
def send_topic(topic, data=None, window_id=None, user_id=None):
data = dumps({"data": data, "topic": topic})
send(window_id=window_id, user_id=user_id, encode_json=False, data=data)
# copy of vispa.AjaxException
class AjaxException(Exception):
"""
AjaxException that is handled by the ajax tool and that can be raised in controller methods.
*message* is the error message to show. *code* should be an integer that represents a specific
type of exception. If *code* is *None* and *message* is an integer representing a http status
code, the error message is set to the standard error message for that http error. If *alert* is
*True*, the message is shown in a dialog in the GUI.
"""
def __init__(self, message, code=None, alert=True):
"""
__init__(message, code=500, alert=True)
"""
if code is None:
if isinstance(message, int) and message in response_codes:
code = message
message = response_codes[code][0]
else:
code = 500
super(AjaxException, self).__init__(message)
self.code = code
self.alert = alert
......@@ -7,8 +7,10 @@ Definition of the vispa ajax tool.
import cherrypy
import json
import vispa
from vispa import log_exception, config, AjaxException
from vispa.controller import strongly_expire
from rpyc.core.vinegar import GenericException
class AjaxTool(cherrypy.Tool):
......@@ -50,18 +52,26 @@ class AjaxTool(cherrypy.Tool):
data = "null"
try:
data = innerfunc(*args, **kwargs)
if not encoded:
data = json.dumps(data)
try:
data = innerfunc(*args, **kwargs)
if not encoded:
data = json.dumps(data)
except (AjaxException, GenericException) as e:
remote_name = "vispa.remote.AjaxException"
if isinstance(e, GenericException) and type(e).__name__ != remote_name:
raise
result["code"] = e.code
result["message"] = e.message
result["alert"] = e.alert
except Exception as e:
raise
except cherrypy.CherryPyException:
raise
except AjaxException as e:
result["code"] = e.code
result["message"] = e.message
result["alert"] = e.alert
except Exception as e:
result["code"] = 500
result["message"] = "an unhandled exception occured"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment