From 487f05dfc641a0632be8bd405add6454cab4f6b0 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Wed, 6 Apr 2022 09:01:07 +0200 Subject: [PATCH] Avoid `TypeError` on `websocket.disconnect` when `code` is `None` (#1574) Co-authored-by: Aber --- starlette/endpoints.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/starlette/endpoints.py b/starlette/endpoints.py index 73367c257..f2468a326 100644 --- a/starlette/endpoints.py +++ b/starlette/endpoints.py @@ -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