Skip to content

Commit

Permalink
Avoid TypeError on websocket.disconnect when code is None (#1574
Browse files Browse the repository at this point in the history
)

Co-authored-by: Aber <Chen_Ye@ahnu.edu.cn>
  • Loading branch information
Kludex and abersheeran committed Apr 6, 2022
1 parent 20d24a8 commit 487f05d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion starlette/endpoints.py
Expand Up @@ -80,7 +80,9 @@ async def dispatch(self) -> None:
data = await self.decode(websocket, message)
await self.on_receive(websocket, data)
elif message["type"] == "websocket.disconnect":
close_code = int(message.get("code", status.WS_1000_NORMAL_CLOSURE))
close_code = int(
message.get("code") or status.WS_1000_NORMAL_CLOSURE
)
break
except Exception as exc:
close_code = status.WS_1011_INTERNAL_ERROR
Expand Down

0 comments on commit 487f05d

Please sign in to comment.