Commit 1e215925 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Add automatic messages to AjaxException.

parent 320759a9
......@@ -23,6 +23,7 @@ import traceback
import copy
import cherrypy
from cherrypy.lib.httputil import response_codes
from . import url
......@@ -259,7 +260,17 @@ class AjaxException(Exception):
"internal server error", etc. If *alert* is *True*, the message is shown in a dialog in the GUI.
"""
def __init__(self, message, code=500, alert=True):
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
......
......@@ -59,7 +59,7 @@ class MethodTool(cherrypy.Tool):
# replaces the original one, otherwise raise a cherrypy.HTTPError
if ajax:
def handler(*args, **kwargs):
raise AjaxException("Method not allowed", code=405)
raise AjaxException(405)
cherrypy.serving.request.handler = handler
else:
raise cherrypy.HTTPError(405)
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