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)
| 1223 | self.finish() |
| 1224 | |
| 1225 | def write_error(self, status_code: int, **kwargs: Any) -> None: |
| 1226 | """Override to implement custom error pages. |
| 1227 | |
| 1228 | ``write_error`` may call `write`, `render`, `set_header`, etc |
| 1229 | to produce output as usual. |
| 1230 | |
| 1231 | If this error was caused by an uncaught exception (including |
| 1232 | HTTPError), an ``exc_info`` triple will be available as |
| 1233 | ``kwargs["exc_info"]``. Note that this exception may not be |
| 1234 | the "current" exception for purposes of methods like |
| 1235 | ``sys.exc_info()`` or ``traceback.format_exc``. |
| 1236 | """ |
| 1237 | if self.settings.get("serve_traceback") and "exc_info" in kwargs: |
| 1238 | # in debug mode, try to send a traceback |
| 1239 | self.set_header("Content-Type", "text/plain") |
| 1240 | for line in traceback.format_exception(*kwargs["exc_info"]): |
| 1241 | self.write(line) |
| 1242 | self.finish() |
| 1243 | else: |
| 1244 | self.finish( |
| 1245 | "<html><title>%(code)d: %(message)s</title>" |
| 1246 | "<body>%(code)d: %(message)s</body></html>" |
| 1247 | % {"code": status_code, "message": self._reason} |
| 1248 | ) |
| 1249 | |
| 1250 | @property |
| 1251 | def locale(self) -> tornado.locale.Locale: |
no test coverage detected