'Sends the given HTTP error code to the browser.
If `flush()` has already been called, it is not possible to send
an error, so this method will simply terminate the response.
If output has been written but not yet flushed, it will be discarded
and replaced with the error page.
Override `write_error()` to customize the error page that is returned.
Additional keyword arguments are passed through to `write_error`.'

def send_error(self, status_code=500, **kwargs):

    if self._headers_written:
        gen_log.error('Cannot    send    error    response    after    headers    written')
        if (not self._finished):
            try:
                self.finish()
            except Exception:
                gen_log.error('Failed    to    flush    partial    response', exc_info=True)
        return
    self.clear()
    reason = kwargs.get('reason')
    if ('exc_info' in kwargs):
        exception = kwargs['exc_info'][1]
        if (isinstance(exception, HTTPError) and exception.reason):
            reason = exception.reason
    self.set_status(status_code, reason=reason)
    try:
        self.write_error(status_code, **kwargs)
    except Exception:
        app_log.error('Uncaught    exception    in    write_error', exc_info=True)
    if (not self._finished):
        self.finish()
