Implement catchable WebsocketClosed
Author: ahopkinsCreated Oct 3, 2021Updated Aug 1, 2026
Labelsintermediatefeature request
See #2220
In v21.9, a new WebsocketClosed exception was added.
While you can to do the following:
@app.websocker("/")
async def handler(request, ws):
try:
...
except asyncio.CancelledError:
print("connection closed")We would like to add support for this pattern:
@app.websocker("/")
async def handler(request, ws):
try:
...
except sanic.exceptions.WebsocketClosed:
print("connection closed")Source: sanic-org/sanic