File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
backend/chatServer/src/chat Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ class ChatException extends WsException {
8
8
this . statusCode = statusCode ;
9
9
}
10
10
11
- getError ( ) : object {
11
+ getError ( ) {
12
12
return {
13
13
statusCode : this . statusCode ,
14
14
msg : this . message ,
@@ -38,6 +38,11 @@ const CHATTING_SOCKET_ERROR = {
38
38
message : '유효하지 않는 유저입니다.'
39
39
} ,
40
40
41
+ UNAUTHORIZED : {
42
+ statusCode : HttpStatus . UNAUTHORIZED ,
43
+ message : '해당 명령에 대한 권한이 없습니다.'
44
+ } ,
45
+
41
46
QUESTION_EMPTY : {
42
47
statusCode : HttpStatus . BAD_REQUEST ,
43
48
message : '유효하지 않은 질문입니다.'
@@ -46,6 +51,11 @@ const CHATTING_SOCKET_ERROR = {
46
51
BAN_USER : {
47
52
statusCode : HttpStatus . FORBIDDEN ,
48
53
message : '호스트에 의해 밴 당한 유저입니다.'
54
+ } ,
55
+
56
+ MSG_TOO_LONG :{
57
+ statusCode : HttpStatus . NOT_ACCEPTABLE ,
58
+ message : '메세지의 내용이 없거나, 길이가 150자를 초과했습니다.'
49
59
}
50
60
51
61
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ export class MessageGuard implements CanActivate {
10
10
canActivate ( context : ExecutionContext ) : boolean {
11
11
const payload = context . switchToWs ( ) . getData ( ) ;
12
12
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 ) ;
14
15
}
15
16
}
16
17
@@ -22,6 +23,7 @@ export class HostGuard implements CanActivate {
22
23
const { roomId, userId } = payload ;
23
24
const hostId = await this . roomService . getHostOfRoom ( roomId ) ;
24
25
console . log ( 'hostGuard:' , hostId , userId ) ;
26
+ if ( hostId !== userId ) throw new ChatException ( CHATTING_SOCKET_ERROR . UNAUTHORIZED , roomId ) ;
25
27
return hostId === userId ;
26
28
}
27
29
}
You can’t perform that action at this time.
0 commit comments