Mercurial > hg > ltpdarepo
changeset 149:d2d83ea3f369
Handle uncaught exceptions with nice error pages.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Wed, 26 Oct 2011 19:59:04 +0200 |
parents | f594c49a3da4 |
children | 80e43dd34d71 |
files | src/ltpdarepo/__init__.py |
diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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 += '<pre>' + traceback.format_exc() + '</pre>' 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')