Re-export Starlette's WebSocketException and add it to docs (#5629)

This commit is contained in:
Sebastián Ramírez authored and GitHub committed 2022-11-13 17:10:54 +01:00
1 parent 1c93d5523a
commit d537ee93d7
4 files changed
+14 -6

No files matched your search

+10 -2
View File
@@ -1,6 +1,14 @@
from typing import Union
from fastapi import Cookie, Depends, FastAPI, Query, WebSocket, status
from fastapi import (
Cookie,
Depends,
FastAPI,
Query,
WebSocket,
WebSocketException,
status,
)
from fastapi.responses import HTMLResponse
app = FastAPI()
@@ -61,7 +69,7 @@ async def get_cookie_or_token(
token: Union[str, None] = Query(default=None),
):
if session is None and token is None:
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
raise WebSocketException(code=status.WS_1008_POLICY_VIOLATION)
return session or token