changeset 4259:e1a63fb9bb4d

Catch configuration errors in the application, not in a debug layer
author Florian Krupicka <florian.krupicka@googlemail.com>
date Fri, 01 Aug 2008 21:29:06 +0200
parents 3f8be25b79cc
children f70003d57e47
files MoinMoin/web/utils.py MoinMoin/wsgiapp.py
diffstat 2 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/utils.py	Fri Aug 01 00:06:14 2008 +0200
+++ b/MoinMoin/web/utils.py	Fri Aug 01 21:29:06 2008 +0200
@@ -10,6 +10,7 @@
 
 from werkzeug.exceptions import abort
 from werkzeug.utils import redirect
+from werkzeug.wrappers import Response
 
 from MoinMoin import log
 from MoinMoin import wikiutil
@@ -253,3 +254,18 @@
         if not count:
             return base
         return u'%s-%d' % (base, count)
+
+FATALTMPL = """
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head><title>%(title)s</title></head>
+<body><h1>%(title)s</h1>
+<pre>
+%(body)s
+</pre></body></html>
+"""
+def fatal_response(error):
+    """ Create a response from MoinMoin.error.FatalError instances. """
+    html = FATALTMPL % dict(title=error.__class__.__name__,
+                            body=str(error))
+    return Response(html, status=500, mimetype='text/html')
--- a/MoinMoin/wsgiapp.py	Fri Aug 01 00:06:14 2008 +0200
+++ b/MoinMoin/wsgiapp.py	Fri Aug 01 21:29:06 2008 +0200
@@ -11,10 +11,10 @@
 
 from MoinMoin.web.contexts import AllContext, Context, XMLRPCContext
 from MoinMoin.web.request import Request, MoinMoinFinish
-from MoinMoin.web.utils import check_forbidden, check_setuid, check_surge_protect
+from MoinMoin.web.utils import check_forbidden, check_setuid, check_surge_protect, fatal_response
 
 from MoinMoin.Page import Page
-from MoinMoin import auth, i18n, user, wikiutil, xmlrpc
+from MoinMoin import auth, i18n, user, wikiutil, xmlrpc, error
 from MoinMoin.action import get_names, get_available_actions
 
 from MoinMoin import log
@@ -253,10 +253,12 @@
         request = Request(environ)
         context = init(request)
         response = run(context)
+        context.clock.stop('total')
     except HTTPException, e:
         response = e
+    except error.ConfigurationError, e:
+        response = fatal_response(e)
 
-    context.clock.stop('total')
     return response(environ, start_response)
 
 class ProxyTrust(object):