Added a function for handling errors coming externally.
authorFredrik Tolf <fredrik@dolda2000.com>
Sat, 11 Jan 2014 04:46:06 +0000 (05:46 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sat, 11 Jan 2014 04:46:06 +0000 (05:46 +0100)
wrw/dispatch.py

index f0326cb..666d7a7 100644 (file)
@@ -55,3 +55,15 @@ def handleenv(env, startreq, handler):
         return proto.simpleerror(env, startreq, 400, "Bad Request", "Request must include Host header.")
     r = req.origrequest(env)
     return handle(r, startreq, handler)
+
+def exterror(env, startreq):
+    def handler(req):
+        import resp
+        code = 404
+        if "Response-Code" in req.ihead:
+            try:
+                code = int(req.ihead["Response-Code"])
+            except ValueError:
+                pass
+        raise resp.httperror(code)
+    return handleenv(env, startreq, handler)