From cfb8b809c1bdd814ce211d9a5dc409e7b6013960 Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Thu, 23 Jun 2011 11:14:16 -0700 Subject: [PATCH] add text tracebacks on 500s when in debug mode --- tornado/web.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tornado/web.py b/tornado/web.py index 55989468e..f0a8d2d5c 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -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 "%(code)d: %(message)s" \ - "%(code)d: %(message)s" % { - "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 "%(code)d: %(message)s" \ + "%(code)d: %(message)s" % { + "code": status_code, + "message": httplib.responses[status_code], + } @property def locale(self): -- 2.47.2