Commit 3bbb2300 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Add docs to AjaxExteption, add alert entry.

parent f8faed5e
......@@ -248,10 +248,18 @@ class Netstat(object):
class AjaxException(Exception):
AjaxException that are 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. Note that this code is meant to extend HTTP status codes, i.e. 500 means
"internal server error", etc. If *alert* is *True*, the message is shown in a dialog in the GUI.
def __init__(self, message, code=500):
def __init__(self, message, code=500, alert=True):
super(AjaxException, self).__init__(message)
self.code = code
self.code = code
self.alert = alert
# the bus
......@@ -21,6 +21,8 @@ class AjaxTool(cherrypy.Tool):
- data: The attached payload with an arbitrary type.
- message: In case of an error, i.e. code != 200, an additional error message. On success,
i.e. code = 200, this should be empty.
- alert: A boolean that desribes whether the error message should be shown in the GUI using a
def __init__(self, point="before_handler", **kwargs):
......@@ -42,25 +44,28 @@ class AjaxTool(cherrypy.Tool):
# the actual result creation is done after the try-except block
result = {
"code" : 200,
"message": None
"message": None,
"alert" : False
data = 'null'
data = "null"
data = innerfunc(*args, **kwargs)
if not encoded:
data = json.dumps(data)
except cherrypy.CherryPyException:
except AjaxException as e:
result["code"] = e.code
result["message"] = e.message
except cherrypy.CherryPyException:
result["alert"] = e.alert
except Exception as e:
result["code"] = 500
result["message"] = "an unhandled exception occured"
result["message"] = "an unhandled exception occured"
result["alert"] = True
if config("vispa", "devmode", False):
result["message"] += ": " + str(e)
Supports Markdown
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