Skip to content

Instantly share code, notes, and snippets.

@dvogel
Created November 4, 2010 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvogel/663167 to your computer and use it in GitHub Desktop.
Save dvogel/663167 to your computer and use it in GitHub Desktop.
Tornado RequestHandler.send_error
def send_error(self, status_code=500, **kwargs):
"""Sends the given HTTP error code to the browser.
We also send the error HTML for the given error code as returned by
get_error_html. Override that method if you want custom error pages
for your application.
"""
if self._headers_written:
logging.error("Cannot send error response after headers written")
if not self._finished:
self.finish()
return
self.clear()
self.set_status(status_code)
message = self.get_error_html(status_code, **kwargs)
self.finish(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment