From 8175734162dda61ed02a6f64ba77620f87a54084 Mon Sep 17 00:00:00 2001 From: hoeeeeeh Date: Mon, 2 Dec 2024 12:08:38 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20ChatException=20throw=20=EC=8B=9C,?= =?UTF-8?q?=20roomId=20=EB=A5=BC=20=EB=8B=B4=EC=95=84=EC=84=9C=20throw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/chatServer/src/chat/chat.gateway.ts | 2 +- backend/chatServer/src/room/room.repository.ts | 6 +++--- backend/chatServer/src/room/room.service.ts | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/chatServer/src/chat/chat.gateway.ts b/backend/chatServer/src/chat/chat.gateway.ts index de7ad5b1..6c4b52a2 100644 --- a/backend/chatServer/src/chat/chat.gateway.ts +++ b/backend/chatServer/src/chat/chat.gateway.ts @@ -176,7 +176,7 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa const banUser = this.server.sockets.sockets.get(socketId); const address = banUser?.handshake.address.replaceAll('::ffff:', ''); - if(!address) throw new ChatException(CHATTING_SOCKET_ERROR.INVALID_USER); + if(!address) throw new ChatException(CHATTING_SOCKET_ERROR.INVALID_USER, roomId); const forwarded = banUser?.handshake.headers.forwarded ?? address; console.log('ban:', roomId, address, forwarded); diff --git a/backend/chatServer/src/room/room.repository.ts b/backend/chatServer/src/room/room.repository.ts index d3908103..18fc4d51 100644 --- a/backend/chatServer/src/room/room.repository.ts +++ b/backend/chatServer/src/room/room.repository.ts @@ -76,7 +76,7 @@ export class RoomRepository { async getHost(roomId: string) { const hostId = await this.redisClient.get(this.getRoomStringWithPrefix(roomId)); - if(!hostId) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if(!hostId) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); return hostId; } @@ -98,7 +98,7 @@ export class RoomRepository { async markQuestionAsDone(roomId: string, questionId: number): Promise { const question = await this.getQuestion(roomId, questionId); - if(!question) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY); + if(!question) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId); question.questionDone = true; this.redisClient.lset(this.getQuestionStringWithPrefix(roomId), questionId, JSON.stringify(question)); return question; @@ -114,7 +114,7 @@ export class RoomRepository { async getQuestion(roomId: string, questionId: number): Promise { const question = await this.lindex>(this.getQuestionStringWithPrefix(roomId), questionId); if(question) return {...question, questionId }; - throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY); + throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId); } async getQuestionId(roomId: string) { diff --git a/backend/chatServer/src/room/room.service.ts b/backend/chatServer/src/room/room.service.ts index e72126ec..f2e16a89 100644 --- a/backend/chatServer/src/room/room.service.ts +++ b/backend/chatServer/src/room/room.service.ts @@ -85,13 +85,13 @@ export class RoomService implements OnModuleInit, OnModuleDestroy { // 방 삭제 async deleteRoom(roomId: string) { const roomExists = await this.redisRepository.isRoomExisted(roomId); - if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); await this.redisRepository.deleteRoom(roomId); } async addQuestion(roomId: string, question: Omit){ const roomExists = await this.redisRepository.isRoomExisted(roomId); - if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); return await this.redisRepository.addQuestionToRoom(roomId, question); } @@ -102,7 +102,7 @@ export class RoomService implements OnModuleInit, OnModuleDestroy { question: Omit, ): Promise { const roomExists = await this.redisRepository.isRoomExisted(roomId); - if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); return await this.redisRepository.addQuestionToRoom(roomId, question); } @@ -110,24 +110,24 @@ export class RoomService implements OnModuleInit, OnModuleDestroy { // 특정 질문 완료 처리 async markQuestionAsDone(roomId: string, questionId: number) { const roomExists = await this.redisRepository.isRoomExisted(roomId); - if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); const markedQuestion = await this.redisRepository.markQuestionAsDone(roomId, questionId); - if (!markedQuestion) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY); + if (!markedQuestion) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId); return markedQuestion; } // 방에 속한 모든 질문 조회 async getQuestions(roomId: string): Promise { const roomExists = await this.redisRepository.isRoomExisted(roomId); - if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); return this.redisRepository.getQuestionsAll(roomId); } async getQuestionsNotDone(roomId: string): Promise { const roomExists = await this.redisRepository.isRoomExisted(roomId); - if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); return this.redisRepository.getQuestionsUnmarked(roomId); } @@ -135,7 +135,7 @@ export class RoomService implements OnModuleInit, OnModuleDestroy { // 특정 질문 조회 async getQuestion(roomId: string, questionId: number): Promise { const roomExists = await this.redisRepository.isRoomExisted(roomId); - if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); return this.redisRepository.getQuestion(roomId, questionId); } @@ -163,7 +163,7 @@ export class RoomService implements OnModuleInit, OnModuleDestroy { async getHostOfRoom(roomId: string) { const roomExists = await this.redisRepository.isRoomExisted(roomId); - if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY); + if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId); return await this.redisRepository.getHost(roomId); }