MCPcopy Create free account
hub / github.com/EasyIME/PIME / send_error

Method send_error

python/python3/tornado/web.py:1187–1223  ·  view source on GitHub ↗

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 er

(self, status_code: int = 500, **kwargs: Any)

Source from the content-addressed store, hash-verified

1185 self.ui = None # type: ignore
1186
1187 def send_error(self, status_code: int = 500, **kwargs: Any) -> None:
1188 """Sends the given HTTP error code to the browser.
1189
1190 If `flush()` has already been called, it is not possible to send
1191 an error, so this method will simply terminate the response.
1192 If output has been written but not yet flushed, it will be discarded
1193 and replaced with the error page.
1194
1195 Override `write_error()` to customize the error page that is returned.
1196 Additional keyword arguments are passed through to `write_error`.
1197 """
1198 if self._headers_written:
1199 gen_log.error("Cannot send error response after headers written")
1200 if not self._finished:
1201 # If we get an error between writing headers and finishing,
1202 # we are unlikely to be able to finish due to a
1203 # Content-Length mismatch. Try anyway to release the
1204 # socket.
1205 try:
1206 self.finish()
1207 except Exception:
1208 gen_log.error("Failed to flush partial response", exc_info=True)
1209 return
1210 self.clear()
1211
1212 reason = kwargs.get("reason")
1213 if "exc_info" in kwargs:
1214 exception = kwargs["exc_info"][1]
1215 if isinstance(exception, HTTPError) and exception.reason:
1216 reason = exception.reason
1217 self.set_status(status_code, reason=reason)
1218 try:
1219 self.write_error(status_code, **kwargs)
1220 except Exception:
1221 app_log.error("Uncaught exception in write_error", exc_info=True)
1222 if not self._finished:
1223 self.finish()
1224
1225 def write_error(self, status_code: int, **kwargs: Any) -> None:
1226 """Override to implement custom error pages.

Callers 3

getMethod · 0.80
getMethod · 0.80

Calls 6

finishMethod · 0.95
clearMethod · 0.95
set_statusMethod · 0.95
write_errorMethod · 0.95
errorMethod · 0.80
getMethod · 0.45

Tested by 2

getMethod · 0.64
getMethod · 0.64