diff --git a/channels/generic/websocket.py b/channels/generic/websocket.py index 6c8ca5769..cacdf3516 100644 --- a/channels/generic/websocket.py +++ b/channels/generic/websocket.py @@ -102,7 +102,7 @@ def websocket_disconnect(self, message): raise InvalidChannelLayerError( "BACKEND is unconfigured or doesn't support groups" ) - self.disconnect(message["code"]) + self.disconnect(message.get("code", 1005)) raise StopConsumer() def disconnect(self, code): @@ -235,7 +235,7 @@ async def websocket_disconnect(self, message): raise InvalidChannelLayerError( "BACKEND is unconfigured or doesn't support groups" ) - await self.disconnect(message["code"]) + await self.disconnect(message.get("code", 1005)) raise StopConsumer() async def disconnect(self, code):