From 905c03a835c9624ba63b5c2bca6b89866837f067 Mon Sep 17 00:00:00 2001 From: hoeeeeeh Date: Mon, 2 Dec 2024 10:42:20 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20init=20data=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatServer/src/room/room.repository.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/backend/chatServer/src/room/room.repository.ts b/backend/chatServer/src/room/room.repository.ts index 5549272a..d3908103 100644 --- a/backend/chatServer/src/room/room.repository.ts +++ b/backend/chatServer/src/room/room.repository.ts @@ -40,23 +40,34 @@ export class RoomRepository { private async lindex(key: string, index: number){ const result = await this.redisClient.lindex(key, index); if(!result) return undefined; - - const l = typeof result === 'string' ? result : JSON.parse(result); - return l as T; + try { + return JSON.parse(result) as T; + } catch { + return result as T; + } } private async lrange(key: string, start: number, end: number){ const result = await this.redisClient.lrange(key, start, end); if(!result) return undefined; - const arrayT = result.map((r) => typeof r === 'string' ? r : JSON.parse(r)); + const arrayT = result.map((r) => { + try { + return JSON.parse(r); + } catch { + return r; + } + }); return arrayT as T; } private async getData(key: string) { const result = await this.redisClient.get(key); if(!result) return undefined; - const data = result === 'string' ? result : JSON.parse(result); - return data as T; + try { + return JSON.parse(result) as T; + } catch { + return result as T; + } } async isRoomExisted(roomId: string) {