diff --git a/server/web2py/applications/vidjil/controllers/default.py b/server/web2py/applications/vidjil/controllers/default.py index 8bb0d4677ba8c6295608dd7b61bb2675470379cf..74e3276321dc7f0cb46e0b1084aef0dfff5c8b1c 100644 --- a/server/web2py/applications/vidjil/controllers/default.py +++ b/server/web2py/applications/vidjil/controllers/default.py @@ -397,7 +397,7 @@ def save_analysis(): ######################################################################### -def handle_error(): +def error(): """ Custom error handler that returns correct status codes, adapted from http://www.web2pyslices.com/slice/show/1529/custom-error-routing @@ -405,25 +405,22 @@ def handle_error(): code = request.vars.code request_url = request.vars.request_url + requested_uri = request.vars.requested_uri ticket = request.vars.ticket + response.status = int(code) - log.error("[%s] %s" % (code, ticket)) + assert(response.status == 500 and request_url != request.url) # avoid infinite loop - if code is not None and request_url != request.url:# Make sure error url is not current url to avoid infinite loop. - response.status = int(code) # Assign the error status code to the current response. (Must be integer to work.) + ticket_url = '%(ticket)s' % { 'host':request.env.http_host, + 'ticket':ticket } + log.error("Server error // %s" % ticket_url) - if code == '403': - return "Not authorized" - elif code == '404': - return "Not found" - elif code == '500': - # Get ticket URL: - ticket_url = "%(ticket)s" % {'scheme':'https','host':request.env.http_host,'ticket':ticket} + user_str, x = log.process('', None) + user_str = user_str.replace('<','').replace('>','') - # Email a notice, etc: - mail.send(to=['contact@vidjil.org'], - subject="[Vidjil] web2py error", - message="Error Ticket: %s" % ticket_url) + mail.send(to=defs.ADMIN_EMAILS, + subject="[Vidjil] Server error - %s" % user_str, + message="Ticket: %s
At: %s
User: %s" % (ticket_url, requested_uri, user_str)) return "Server error"