# HG changeset patch # User Daniele Nicolodi # Date 1319651944 -7200 # Node ID d2d83ea3f369a3df62618ad3168d346548837ec5 # Parent f594c49a3da4fe9291665f75ad4ae1b7738d5d01 Handle uncaught exceptions with nice error pages. diff -r f594c49a3da4 -r d2d83ea3f369 src/ltpdarepo/__init__.py --- a/src/ltpdarepo/__init__.py Fri Oct 21 19:04:34 2011 +0200 +++ b/src/ltpdarepo/__init__.py Wed Oct 26 19:59:04 2011 +0200 @@ -1,7 +1,7 @@ from urlparse import urlparse, urljoin from flask import Flask, g, request, session, render_template, Markup, redirect, flash, url_for -from werkzeug.exceptions import InternalServerError +from werkzeug.exceptions import default_exceptions, InternalServerError, HTTPException from pkg_resources import get_distribution import MySQLdb as mysql @@ -44,11 +44,16 @@ # register error handlers -from werkzeug import exceptions -def error_handler(error): +def _error_handler(error): + if not isinstance(error, HTTPException): + # nicely report tracebacks + import traceback + error = InternalServerError() + error.description += '
' + traceback.format_exc() + '
' return render_template('error.html', error=error), error.code -for exc in exceptions.default_exceptions: - app.error_handler_spec[None][exc] = error_handler + +for exc in default_exceptions: + app.error_handler_spec[None][exc] = _error_handler @app.template_filter('breadcrumbs')