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) {