From 7170b86724243716f269ba86b4372a68030a4f7b Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sat, 14 Jan 2023 13:22:09 +0100 Subject: [PATCH] fixup: websocket data parsing + logger --- packages/backend/src/server/api/stream/index.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/stream/index.ts b/packages/backend/src/server/api/stream/index.ts index 145c318fa..8ece8e0ff 100644 --- a/packages/backend/src/server/api/stream/index.ts +++ b/packages/backend/src/server/api/stream/index.ts @@ -13,6 +13,9 @@ import { readNotification } from '../common/read-notification.js'; import channels from './channels/index.js'; import Channel from './channel.js'; import { StreamEventEmitter, StreamMessages } from './types.js'; +import Logger from '@/services/logger.js'; + +const logger = new Logger('streaming'); /** * Main stream connection @@ -123,13 +126,17 @@ export class Connection { } private async onMessage(data: WebSocket.RawData, isRaw: boolean) { - if (data.isRaw) return; + if (isRaw) { + logger.warn('received unexpected raw data from websocket'); + return; + } let obj: Record; try { - obj = JSON.parse(data.utf8Data); - } catch (e) { + obj = JSON.parse(data); + } catch (err) { + logger.error(err); return; }