Skip to content

Commit 8175734

Browse files
committed
refactor: ChatException throw 시, roomId 를 담아서 throw
1 parent 905c03a commit 8175734

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

backend/chatServer/src/chat/chat.gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
176176
const banUser = this.server.sockets.sockets.get(socketId);
177177
const address = banUser?.handshake.address.replaceAll('::ffff:', '');
178178

179-
if(!address) throw new ChatException(CHATTING_SOCKET_ERROR.INVALID_USER);
179+
if(!address) throw new ChatException(CHATTING_SOCKET_ERROR.INVALID_USER, roomId);
180180

181181
const forwarded = banUser?.handshake.headers.forwarded ?? address;
182182
console.log('ban:', roomId, address, forwarded);

backend/chatServer/src/room/room.repository.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class RoomRepository {
7676

7777
async getHost(roomId: string) {
7878
const hostId = await this.redisClient.get(this.getRoomStringWithPrefix(roomId));
79-
if(!hostId) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
79+
if(!hostId) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
8080
return hostId;
8181
}
8282

@@ -98,7 +98,7 @@ export class RoomRepository {
9898

9999
async markQuestionAsDone(roomId: string, questionId: number): Promise<QuestionDto> {
100100
const question = await this.getQuestion(roomId, questionId);
101-
if(!question) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY);
101+
if(!question) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId);
102102
question.questionDone = true;
103103
this.redisClient.lset(this.getQuestionStringWithPrefix(roomId), questionId, JSON.stringify(question));
104104
return question;
@@ -114,7 +114,7 @@ export class RoomRepository {
114114
async getQuestion(roomId: string, questionId: number): Promise<QuestionDto> {
115115
const question = await this.lindex<Omit<QuestionDto, 'questionId'>>(this.getQuestionStringWithPrefix(roomId), questionId);
116116
if(question) return {...question, questionId };
117-
throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY);
117+
throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId);
118118
}
119119

120120
async getQuestionId(roomId: string) {

backend/chatServer/src/room/room.service.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ export class RoomService implements OnModuleInit, OnModuleDestroy {
8585
// 방 삭제
8686
async deleteRoom(roomId: string) {
8787
const roomExists = await this.redisRepository.isRoomExisted(roomId);
88-
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
88+
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
8989
await this.redisRepository.deleteRoom(roomId);
9090
}
9191

9292
async addQuestion(roomId: string, question: Omit<QuestionDto, 'questionId'>){
9393
const roomExists = await this.redisRepository.isRoomExisted(roomId);
94-
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
94+
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
9595

9696
return await this.redisRepository.addQuestionToRoom(roomId, question);
9797
}
@@ -102,40 +102,40 @@ export class RoomService implements OnModuleInit, OnModuleDestroy {
102102
question: Omit<QuestionDto, 'questionId'>,
103103
): Promise<QuestionDto> {
104104
const roomExists = await this.redisRepository.isRoomExisted(roomId);
105-
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
105+
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
106106

107107
return await this.redisRepository.addQuestionToRoom(roomId, question);
108108
}
109109

110110
// 특정 질문 완료 처리
111111
async markQuestionAsDone(roomId: string, questionId: number) {
112112
const roomExists = await this.redisRepository.isRoomExisted(roomId);
113-
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
113+
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
114114

115115
const markedQuestion = await this.redisRepository.markQuestionAsDone(roomId, questionId);
116-
if (!markedQuestion) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY);
116+
if (!markedQuestion) throw new ChatException(CHATTING_SOCKET_ERROR.QUESTION_EMPTY, roomId);
117117
return markedQuestion;
118118
}
119119

120120
// 방에 속한 모든 질문 조회
121121
async getQuestions(roomId: string): Promise<QuestionDto[]> {
122122
const roomExists = await this.redisRepository.isRoomExisted(roomId);
123-
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
123+
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
124124

125125
return this.redisRepository.getQuestionsAll(roomId);
126126
}
127127

128128
async getQuestionsNotDone(roomId: string): Promise<QuestionDto[]> {
129129
const roomExists = await this.redisRepository.isRoomExisted(roomId);
130-
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
130+
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
131131

132132
return this.redisRepository.getQuestionsUnmarked(roomId);
133133
}
134134

135135
// 특정 질문 조회
136136
async getQuestion(roomId: string, questionId: number): Promise<QuestionDto> {
137137
const roomExists = await this.redisRepository.isRoomExisted(roomId);
138-
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
138+
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
139139
return this.redisRepository.getQuestion(roomId, questionId);
140140
}
141141

@@ -163,7 +163,7 @@ export class RoomService implements OnModuleInit, OnModuleDestroy {
163163

164164
async getHostOfRoom(roomId: string) {
165165
const roomExists = await this.redisRepository.isRoomExisted(roomId);
166-
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY);
166+
if (!roomExists) throw new ChatException(CHATTING_SOCKET_ERROR.ROOM_EMPTY, roomId);
167167
return await this.redisRepository.getHost(roomId);
168168
}
169169

0 commit comments

Comments
 (0)