starlette
starlette copied to clipboard
Fix: Raise WebSocketDisconnect instead of RuntimeError on closed conn…
Summary
Replaces the generic RuntimeError with WebSocketDisconnect (code 1006) when attempting to send or receive messages on a WebSocket connection that has already been closed.
This improves error handling by allowing applications to catch a specific exception type instead of relying on string matching for RuntimeError.
Fixes #2767.
Checklist
- [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- [x] I've updated the documentation accordingly. (No doc changes needed for this internal fix, but tests are updated)