基于一些谷歌搜索,我安装了以下错误处理程序。然而,似乎返回 http 500 的 python 异常并没有被这些东西所困,尽管 404 是。使用我在下面的代码中留下的打印语句,我可以看到它没有遇到任何这些例程。我真的应该做什么?
class ErrorHandler(tornado.web.RequestHandler):
"""Generates an error response with status_code for all requests."""
def __init__ (self, application, request, status_code):
print 'In ErrorHandler init'
tornado.web.RequestHandler.__init__(self, application, request)
self.set_status(status_code)
def get_error_html (self, status_code, **kwargs):
print 'In get_error_html. status_code: ', status_code
if status_code in [403, 404, 500, 503]:
filename = '%d.html' % status_code
print 'rendering filename: ', filename
return self.render_string(filename, title=config.get_title())
return "<html><title>%(code)d: %(message)s</title>" \
"<body class='bodyErrorPage'>%(code)d: %(message)s</body>"\
"</html>" % {
"code": status_code,
"message": httplib.responses[status_code],
}
def prepare (self):
print 'In prepare...'
raise tornado.web.HTTPError(self._status_code)