From 523745a562104b7c89e29f9f3d284a9688343438 Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Sun, 30 Dec 2012 09:33:06 -0800 Subject: Return 404s instead of 500s for many error cases. --- web/controller.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/controller.py b/web/controller.py index 2275733..b4f5189 100644 --- a/web/controller.py +++ b/web/controller.py @@ -517,12 +517,21 @@ def database_connect(): sys.exit(1) return database +def handle_error(): + """Handle any unhandled exceptions. + It turns out a lot of our code raises exceptions that cause 500's for users + Instead of raising a 500 (for say, an invalid atom) simply return a 404 + instead. The exception should still get logged. + """ + cherrypy.response.status = 404 + def main(): """Use this when we run standalone""" # site-wide config cherrypy.config.update({ #'environment': 'production', + 'response.error_response' = handle_error, 'log.screen': True, 'log.error_file': '/tmp/cherrypy_packages2.gentoo.log', @@ -575,7 +584,7 @@ def setup_server(): # if something goes wrong, we get a log. cherrypy.config.update({ #'environment': 'production', - + 'response.error_response' = handle_error, 'log.screen': False, 'log.error_file': '/tmp/cherrypy_packages2.gentoo.log', -- cgit v1.2.3-65-gdbad