MCPcopy
hub / github.com/tornadoweb/tornado / write_error

Method write_error

tornado/web.py:1386–1409  ·  view source on GitHub ↗

Override to implement custom error pages. ``write_error`` may call `write`, `render`, `set_header`, etc to produce output as usual. If this error was caused by an uncaught exception (including HTTPError), an ``exc_info`` triple will be available as ``kwargs[

(self, status_code: int, **kwargs: Any)

Source from the content-addressed store, hash-verified

1384 self.finish()
1385
1386 def write_error(self, status_code: int, **kwargs: Any) -> None:
1387 """Override to implement custom error pages.
1388
1389 ``write_error`` may call `write`, `render`, `set_header`, etc
1390 to produce output as usual.
1391
1392 If this error was caused by an uncaught exception (including
1393 HTTPError), an ``exc_info`` triple will be available as
1394 ``kwargs["exc_info"]``. Note that this exception may not be
1395 the "current" exception for purposes of methods like
1396 ``sys.exc_info()`` or ``traceback.format_exc``.
1397 """
1398 if self.settings.get("serve_traceback") and "exc_info" in kwargs:
1399 # in debug mode, try to send a traceback
1400 self.set_header("Content-Type", "text/plain")
1401 for line in traceback.format_exception(*kwargs["exc_info"]):
1402 self.write(line)
1403 self.finish()
1404 else:
1405 self.finish(
1406 "<html><title>%(code)d: %(message)s</title>"
1407 "<body>%(code)d: %(message)s</body></html>"
1408 % {"code": status_code, "message": escape.xhtml_escape(self._reason)}
1409 )
1410
1411 @property
1412 def locale(self) -> tornado.locale.Locale:

Callers 1

send_errorMethod · 0.95

Calls 4

set_headerMethod · 0.95
writeMethod · 0.95
finishMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected