From a57682d5dc12695ed8fb8c9cfb81f7244f20a7d7 Mon Sep 17 00:00:00 2001 From: Pat Pannuto Date: Sat, 4 Apr 2015 15:55:13 -0400 Subject: [PATCH] Add generic exception catcher --- chezbetty/__init__.py | 2 ++ chezbetty/templates/exception.jinja2 | 19 +++++++++++++++++++ chezbetty/views.py | 17 +++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 chezbetty/templates/exception.jinja2 diff --git a/chezbetty/__init__.py b/chezbetty/__init__.py index bd76f6f..2110ded 100644 --- a/chezbetty/__init__.py +++ b/chezbetty/__init__.py @@ -74,6 +74,8 @@ def debug(request): config.add_static_view('static', 'static', cache_max_age=3600) + config.add_route('exception_view', '/exception') + config.add_route('index', '/') config.add_route('lang', '/lang-{code}') diff --git a/chezbetty/templates/exception.jinja2 b/chezbetty/templates/exception.jinja2 new file mode 100644 index 0000000..ab546fc --- /dev/null +++ b/chezbetty/templates/exception.jinja2 @@ -0,0 +1,19 @@ +{% extends "base.jinja2" %} +{% block title %}An Unknown Error Occurred{% endblock %} + +{% block content %} + +

An unknown error occurred

+ +

Please e-mail chez-betty@umich.edu with a brief description of what you were +doing when this error occurred. Please include the rough time of the error as +well.

+ +
+ + + Sorry for the trouble. Touch here to return to the home page. + + +{% endblock %} + diff --git a/chezbetty/views.py b/chezbetty/views.py index 3738c8b..1198f6b 100644 --- a/chezbetty/views.py +++ b/chezbetty/views.py @@ -33,10 +33,27 @@ import binascii import transaction +import traceback + class DepositException(Exception): pass +### +### Catch-all error page +### + +@view_config(route_name='exception_view', renderer='templates/exception.jinja2') +def exception_view(request): + return {} + +@view_config(context=Exception) +def exception_view_handler(context, request): + print('An unknown error occurred:') + traceback.print_exc() + return HTTPFound(location=request.route_url('exception_view')) + + ### ### HTML Pages ###