Skip to content

Commit 8fb89c6

Browse files
committed
feat: Chat Exception 세분화
1 parent 8175734 commit 8fb89c6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

backend/chatServer/src/chat/chat.error.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ChatException extends WsException {
88
this.statusCode = statusCode;
99
}
1010

11-
getError(): object {
11+
getError() {
1212
return {
1313
statusCode: this.statusCode,
1414
msg: this.message,
@@ -38,6 +38,11 @@ const CHATTING_SOCKET_ERROR = {
3838
message: '유효하지 않는 유저입니다.'
3939
},
4040

41+
UNAUTHORIZED: {
42+
statusCode: HttpStatus.UNAUTHORIZED,
43+
message: '해당 명령에 대한 권한이 없습니다.'
44+
},
45+
4146
QUESTION_EMPTY: {
4247
statusCode: HttpStatus.BAD_REQUEST,
4348
message: '유효하지 않은 질문입니다.'
@@ -46,6 +51,11 @@ const CHATTING_SOCKET_ERROR = {
4651
BAN_USER: {
4752
statusCode: HttpStatus.FORBIDDEN,
4853
message: '호스트에 의해 밴 당한 유저입니다.'
54+
},
55+
56+
MSG_TOO_LONG:{
57+
statusCode: HttpStatus.NOT_ACCEPTABLE,
58+
message: '메세지의 내용이 없거나, 길이가 150자를 초과했습니다.'
4959
}
5060

5161

backend/chatServer/src/chat/chat.guard.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export class MessageGuard implements CanActivate {
1010
canActivate(context: ExecutionContext): boolean {
1111
const payload = context.switchToWs().getData();
1212
const { msg } = payload;
13-
return !!msg && msg.length <= 150;
13+
if(!!msg && msg.length <= 150) return true;
14+
throw new ChatException(CHATTING_SOCKET_ERROR.MSG_TOO_LONG);
1415
}
1516
}
1617

@@ -22,6 +23,7 @@ export class HostGuard implements CanActivate {
2223
const { roomId, userId } = payload;
2324
const hostId = await this.roomService.getHostOfRoom(roomId);
2425
console.log('hostGuard:', hostId, userId);
26+
if (hostId !== userId) throw new ChatException(CHATTING_SOCKET_ERROR.UNAUTHORIZED, roomId);
2527
return hostId === userId;
2628
}
2729
}

0 commit comments

Comments
 (0)