mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-06 04:57:58 -05:00
✨ Re-export Starlette's WebSocketException and add it to docs (#5629)
This commit is contained in:
committed by
GitHub
parent
1c93d5523a
commit
d537ee93d7
@@ -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