Browse files

Include a formatted exception in WSGI error page.

  • Loading branch information...
1 parent 116fcfc commit d42fdc4ff6a228f098e9e12a2aeec9737748dfcc @cortesi committed May 7, 2012
Showing with 8 additions and 6 deletions.
  1. +1 −1 libmproxy/dump.py
  2. +7 −5 libmproxy/wsgi.py
View
2 libmproxy/dump.py
@@ -214,12 +214,12 @@ def handle_error(self, msg):
self._process_flow(f)
return f
+# begin nocover
def shutdown(self):
if self.o.wfile:
self.wfile.fo.close()
return flow.FlowMaster.shutdown(self)
-# begin nocover
def run(self):
if self.o.rfile and not self.o.keepserving:
if self.script:
View
12 libmproxy/wsgi.py
@@ -1,4 +1,4 @@
-import cStringIO, urllib, time, sys
+import cStringIO, urllib, time, sys, traceback
import version, flow
def date_time_string():
@@ -55,18 +55,19 @@ def make_environ(self, request, errsoc):
environ[key] = value
return environ
- def error_page(self, soc, headers_sent):
+ def error_page(self, soc, headers_sent, s):
"""
Make a best-effort attempt to write an error page. If headers are
already sent, we just bung the error into the page.
"""
c = """
<html>
<h1>Internal Server Error</h1>
+ <pre>%s"</pre>
</html>
- """
+ """%s
if not headers_sent:
- soc.write("HTTP/1.1 500 Internal Server Error%s\r\n")
+ soc.write("HTTP/1.1 500 Internal Server Error\r\n")
soc.write("Content-Type: text/html\r\n")
soc.write("Content-Length: %s\r\n"%len(c))
soc.write("\r\n")
@@ -115,7 +116,8 @@ def start_response(status, headers, exc_info=None):
write("")
except Exception, v:
try:
- self.error_page(soc, state["headers_sent"])
+ s = traceback.format_exc()
+ self.error_page(soc, state["headers_sent"], s)
# begin nocover
except Exception, v:
pass

0 comments on commit d42fdc4

Please sign in to comment.