'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["exc_info"]``.  Note that this exception may not be
the "current" exception for purposes of methods like
``sys.exc_info()`` or ``traceback.format_exc``.'

def write_error(self, status_code, **kwargs):

    if (self.settings.get('serve_traceback') and ('exc_info' in kwargs)):
        self.set_header('Content-Type', 'text/plain')
        for line in traceback.format_exception(*kwargs['exc_info']):
            self.write(line)
        self.finish()
    else:
        self.finish(('<html><title>%(code)d:    %(message)s</title><body>%(code)d:    %(message)s</body></html>' % {'code': status_code, 'message': self._reason}))
