mirror of
https://github.com/fastapi/fastapi.git
synced 2026-09-16 07:19:43 -04:00
✨ Re-export Starlette's WebSocketException and add it to docs (#5629)
This commit is contained in:
1 parent
1c93d5523a
commit
d537ee93d7
4 files changed
+14
-6
No files matched your search
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user