def _handle_request_exception(self, e):
if isinstance(e, Finish):
# Not an error; just finish the request without logging.
if not self._finished:
self.finish(*e.args)
return
try:
self.log_exception(*sys.exc_info())
except Exception:
app_log.error("Error in exception logger", exc_info=True)
if self._finished:
return
if isinstance(e, HTTPError):
self.response(e)
else:
self.response(HTTPError(log_message=repr(e)))
python类Finish()的实例源码
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def emit(self, data):
if type(data) is not str:
serialized_data = json.dumps(data)
else:
serialized_data = data
try:
self.write('data: {}\n\n'.format(serialized_data))
await self.flush()
except StreamClosedError:
app_log.warning("Stream closed while handling %s", self.request.uri)
# raise Finish to halt the handler
raise web.Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
self.write('authentication required')
raise Finish()
def cursor(self):
cursor = self.get_argument('cursor', None)
if cursor:
try:
cursor = int(cursor)
except ValueError:
self.redirect(self.request.path, permanent=True)
raise Finish()
if cursor < 0:
raise HTTPError(404)
else:
cursor = None
return cursor
def _handle_request_exception(self, e):
from tornado.web import Finish, app_log, gen_log, HTTPError, httputil
if isinstance(e, Finish):
# Not an error; just finish the request without logging.
if not self._finished:
self.finish(*e.args)
return
## add
if isinstance(e, params.InvalidParams):
self.set_status(400)
self.finish({'error': str(e)})
return
## end
try:
self.log_exception(*sys.exc_info())
except Exception:
# An error here should still get a best-effort send_error()
# to avoid leaking the connection.
app_log.error("Error in exception logger", exc_info=True)
if self._finished:
# Extra errors after the request has been finished should
# be logged, but there is no reason to continue to try and
# send a response.
return
if isinstance(e, HTTPError):
if e.status_code not in httputil.responses and not e.reason:
gen_log.error("Bad HTTP status code: %d", e.status_code)
self.send_error(500, exc_info=sys.exc_info())
else:
self.send_error(e.status_code, exc_info=sys.exc_info())
else:
self.send_error(500, exc_info=sys.exc_info())
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()