Handle exceptions in do_hgweb: Send "Internal Server Error", log traceback
authorThomas Arendsen Hein <thomas@intevation.de>
Tue, 02 Jan 2007 22:12:38 +0100
changeset 4015 769be3c57564
parent 4014 509342f95564
child 4016 a195f11ed1a2
child 4025 d8b3edf88af0
Handle exceptions in do_hgweb: Send "Internal Server Error", log traceback
mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py	Fri Dec 29 06:37:43 2006 +0100
+++ b/mercurial/hgweb/server.py	Tue Jan 02 22:12:38 2007 +0100
@@ -8,7 +8,7 @@
 
 from mercurial.demandload import demandload
 import os, sys, errno
-demandload(globals(), "urllib BaseHTTPServer socket SocketServer")
+demandload(globals(), "urllib BaseHTTPServer socket SocketServer traceback")
 demandload(globals(), "mercurial:ui,hg,util,templater")
 demandload(globals(), "hgweb_mod:hgweb hgwebdir_mod:hgwebdir request:wsgiapplication")
 from mercurial.i18n import gettext as _
@@ -55,10 +55,17 @@
 
     def do_POST(self):
         try:
-            self.do_hgweb()
-        except socket.error, inst:
-            if inst[0] != errno.EPIPE:
-                raise
+            try:
+                self.do_hgweb()
+            except socket.error, inst:
+                if inst[0] != errno.EPIPE:
+                    raise
+        except StandardError, inst:
+            self._start_response("500 Internal Server Error", [])
+            self._write("Internal Server Error")
+            tb = "".join(traceback.format_exception(*sys.exc_info()))
+            self.log_error("Exception happened during processing request '%s':\n%s",
+                           self.path, tb)
 
     def do_GET(self):
         self.do_POST()