Recover from errors writing the response

This commit is contained in:
Miguel Grinberg
2022-09-17 23:11:19 +01:00
parent 59453a52a1
commit dc7a041ebd

View File

@@ -986,15 +986,17 @@ class Microdot():
res = self.dispatch_request(req)
except Exception as exc: # pragma: no cover
print_exception(exc)
try:
if res and res != Response.already_handled: # pragma: no branch
res.write(stream)
try:
stream.close()
except OSError as exc: # pragma: no cover
if exc.errno in MUTED_SOCKET_ERRORS:
pass
else:
raise
print_exception(exc)
except Exception as exc: # pragma: no cover
print_exception(exc)
if stream != sock: # pragma: no cover
sock.close()
if self.shutdown_requested: # pragma: no cover