]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
add text tracebacks on 500s when in debug mode 289/head
authorEvan Klitzke <evan@eklitzke.org>
Thu, 23 Jun 2011 18:14:16 +0000 (11:14 -0700)
committerEvan Klitzke <evan@eklitzke.org>
Thu, 23 Jun 2011 18:18:25 +0000 (11:18 -0700)
tornado/web.py

index 55989468e22101b0cacb5b28771cf6c257adb472..f0a8d2d5c41288960af45debf333f7341c026568 100644 (file)
@@ -70,6 +70,7 @@ import stat
 import sys
 import time
 import tornado
+import traceback
 import types
 import urllib
 import urlparse
@@ -663,11 +664,16 @@ class RequestHandler(object):
         If this error was caused by an uncaught exception, the
         exception object can be found in kwargs e.g. kwargs['exception']
         """
-        return "<html><title>%(code)d: %(message)s</title>" \
-               "<body>%(code)d: %(message)s</body></html>" % {
-            "code": status_code,
-            "message": httplib.responses[status_code],
-        }
+        if self.settings.get("debug"):
+            # in debug mode, try to send a traceback
+            self.set_header('Content-Type', 'text/plain')
+            return traceback.format_exc()
+        else:
+            return "<html><title>%(code)d: %(message)s</title>" \
+                   "<body>%(code)d: %(message)s</body></html>" % {
+                "code": status_code,
+                "message": httplib.responses[status_code],
+            }
 
     @property
     def locale(self):