Catch websocket disconnect (#184)

This commit is contained in:
Nikhil Rao 2022-12-26 23:14:35 -08:00 committed by GitHub
parent af9733996a
commit a93b1425c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ from typing import Any, Callable, Coroutine, Dict, List, Optional, Tuple, Type,
from fastapi import FastAPI, WebSocket
from fastapi.middleware import cors
from starlette.websockets import WebSocketDisconnect
from pynecone import constants, utils
from pynecone.base import Base
@ -320,7 +321,11 @@ def _event(app: App):
# Process events until the connection is closed.
while True:
# Get the event.
event = Event.parse_raw(await websocket.receive_text())
try:
event = Event.parse_raw(await websocket.receive_text())
except WebSocketDisconnect:
# Close the connection.
return
# Process the event.
update = await process(app, event)