Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log non-text messages in websocket api #530

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion matter_server/client/connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Logic to manage the WebSocket connection to the Matter server."""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -121,7 +122,9 @@ async def receive_message_or_raise(self) -> MessageType:
raise ConnectionFailed()

if ws_msg.type != WSMsgType.TEXT:
raise InvalidMessage(f"Received non-Text message: {ws_msg.type}")
raise InvalidMessage(
f"Received non-Text message: {ws_msg.type}: {ws_msg.data}"
)

try:
msg = parse_message(json_loads(ws_msg.data))
Expand Down
13 changes: 9 additions & 4 deletions matter_server/server/client_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Logic to handle a client connected over WebSockets."""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -67,7 +68,7 @@ async def disconnect(self) -> None:

async def handle_client(self) -> web.WebSocketResponse:
"""Handle a websocket response."""
# pylint: disable=too-many-branches
# pylint: disable=too-many-branches,too-many-statements
request = self.request
wsock = self.wsock
try:
Expand All @@ -91,13 +92,17 @@ async def handle_client(self) -> web.WebSocketResponse:
while not wsock.closed:
msg = await wsock.receive()

if msg.type in (WSMsgType.CLOSE, WSMsgType.CLOSING):
if msg.type in (WSMsgType.CLOSED, WSMsgType.CLOSE, WSMsgType.CLOSING):
break

if msg.type != WSMsgType.TEXT:
disconnect_warn = "Received non-Text message."
if msg.type == WSMsgType.ERROR:
disconnect_warn = f"Received error message: {msg.data}"
break

if msg.type != WSMsgType.TEXT:
self._logger.debug("Received non-Text message: %s", msg.data)
continue

self._logger.debug("Received: %s", msg.data)

try:
Expand Down