changeset 4015:769be3c57564

Handle exceptions in do_hgweb: Send "Internal Server Error", log traceback
author Thomas Arendsen Hein <thomas@intevation.de>
date Tue, 02 Jan 2007 22:12:38 +0100
parents 509342f95564
children a195f11ed1a2 d8b3edf88af0
files mercurial/hgweb/server.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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()