调整校验顺序,优先处理json

This commit is contained in:
Chingfeng Li 2025-08-26 17:48:42 +08:00
parent 2005fe220e
commit d04264b878

View file

@ -17,12 +17,8 @@ class TextMessageProcessor:
# 解析JSON消息 # 解析JSON消息
msg_json = json.loads(message) msg_json = json.loads(message)
# 处理纯数字消息 # 处理JSON消息
if isinstance(msg_json, int): if isinstance(msg_json, dict):
conn.logger.bind(tag=TAG).info(f"收到文本消息:{message}")
await conn.websocket.send(message)
return
message_type = msg_json.get("type") message_type = msg_json.get("type")
# 记录日志 # 记录日志
@ -34,6 +30,10 @@ class TextMessageProcessor:
await handler.handle(conn, msg_json) await handler.handle(conn, msg_json)
else: else:
conn.logger.bind(tag=TAG).error(f"收到未知类型消息:{message}") conn.logger.bind(tag=TAG).error(f"收到未知类型消息:{message}")
# 处理纯数字消息
elif isinstance(msg_json, int):
conn.logger.bind(tag=TAG).info(f"收到数字消息:{message}")
await conn.websocket.send(message)
except json.JSONDecodeError: except json.JSONDecodeError:
# 非JSON消息直接转发 # 非JSON消息直接转发