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

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

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