def write_error(self, status_code, **kwargs):
"""
Method gets traceback, writes it into response, finishes response.
:param status_code: tornado parameter to format html, we don't use it.
:type status_code: int
:param kwargs: in debug mode must contain exc_info.
:type kwargs: dict
"""
exc_info = kwargs.get('exc_info')
if self.settings.get(
"serve_traceback") and exc_info: # pragma: no cover
# in debug mode, try to send a traceback
self.set_header('Content-Type', 'text/plain')
for line in traceback.format_exception(*exc_info):
self.write(line)
# exc_info[1] - HTTPError instance
# Finish request with exception body or exception reason
err_text = getattr(exc_info[1], 'body', self._reason)
self.write(err_text)
self.finish()
评论列表
文章目录