while reworking Fastapi WebSockets tutorial received error on websocket connection lost, because of web page close or reload.
RuntimeError: Cannot call "receive" once a disconnect message has been received.
it was not critical, nor crash server. but leaving it be does no feels wright.
how to handle this WebSocket error?
-
A way to handle this error notification was to add try / except RuntimeError
while True:
try:
msg = await websocket.receive()
except RuntimeError:
break