Dolda2000 GitWeb
/
wrw.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e88ff53
)
Use the env module to catch errors in the dispatcher.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Sun, 5 Feb 2012 15:44:08 +0000
(16:44 +0100)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Sun, 5 Feb 2012 15:44:08 +0000
(16:44 +0100)
wrw/dispatch.py
patch
|
blob
|
blame
|
history
diff --git
a/wrw/dispatch.py
b/wrw/dispatch.py
index
fe62df3
..
15ea99e
100644
(file)
--- a/
wrw/dispatch.py
+++ b/
wrw/dispatch.py
@@
-1,3
+1,6
@@
+import sys, traceback
+import env
+
__all__ = ["restart"]
class restart(Exception):
__all__ = ["restart"]
class restart(Exception):
@@
-39,7
+42,20
@@
class iterproxy(object):
if hasattr(self.bk, "close"):
self.bk.close()
if hasattr(self.bk, "close"):
self.bk.close()
+def defaulterror(req, excinfo):
+ import resp
+ traceback.print_exception(*excinfo)
+ raise resp.httperror(500)
+
+def wraphandler(handler, excinfo):
+ def wrapped(req):
+ return handler(req, excinfo)
+ return wrapped
+
+errorhandler = env.var(defaulterror)
+
def handle(req, startreq, handler):
def handle(req, startreq, handler):
+ eh = errorhandler.val
try:
resp = [""]
while True:
try:
resp = [""]
while True:
@@
-48,6
+64,11
@@
def handle(req, startreq, handler):
break
except restart, i:
handler = i.handle
break
except restart, i:
handler = i.handle
+ except Exception, i:
+ if eh is None:
+ raise
+ handler = wraphandler(eh, sys.exc_info())
+ eh = None
req.commit(startreq)
return resp
finally:
req.commit(startreq)
return resp
finally: