-
-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace WebSocket assertions with RuntimeError #1472
Replace WebSocket assertions with RuntimeError #1472
Conversation
async def asgi(receive, send): | ||
websocket = WebSocket(scope, receive=receive, send=send) | ||
await websocket.accept() | ||
websocket.client_state = WebSocketState.CONNECTING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't test this without modifying the client state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great yup! I've got a small suggestion on the text for the four message_type
cases, which I'll address inline.
if message_type != "websocket.connect": | ||
raise RuntimeError( | ||
'WebSocket is not connected. Need to call "accept" first.' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we think about this kind of style for the message_type
case?...
f'Expected ASGI message "websocket.connect", but got {message_type!r}'
…com:aminalaee/starlette into switch-websockets-asserts-with-runtimeerror
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
What version of |
@dave-fitzgerald-bc It will be available in |
Fixes #1471.
Switching public facing WebSocket assertions to RuntimeError.