Skip to content

Commit 28365ba

Browse files
committed
fix : 닉네임 중복 오류 메시지 응답
1 parent e3589fd commit 28365ba

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

api/src/main/java/com/mbtips/common/handler/WebSocketChatHandler.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import lombok.extern.slf4j.Slf4j;
1111
import org.springframework.stereotype.Component;
1212
import org.springframework.web.socket.CloseStatus;
13+
import org.springframework.web.socket.TextMessage;
1314
import org.springframework.web.socket.WebSocketMessage;
1415
import org.springframework.web.socket.WebSocketSession;
1516
import org.springframework.web.socket.handler.TextWebSocketHandler;
@@ -38,7 +39,7 @@ public class WebSocketChatHandler extends TextWebSocketHandler {
3839

3940
// 연결
4041
@Override
41-
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
42+
public void afterConnectionEstablished(WebSocketSession session) throws IOException {
4243
String query = session.getUri().getQuery();
4344
log.info("{} connected", query);
4445

@@ -50,6 +51,9 @@ public void afterConnectionEstablished(WebSocketSession session) throws Exceptio
5051
Map<String, String> queryParamMap = this.parseQueryParam(query);
5152
long openChatId = Long.parseLong(queryParamMap.get(OPEN_CHAT_ID));
5253
if (this.checkNickname(openChatId, queryParamMap.get(NICKNAME))) {
54+
String string = OpenChatException.DUPLICATED_NICKNAME.getMessage();
55+
byte[] bytes = string.getBytes();
56+
session.sendMessage(new TextMessage(bytes));
5357
throw new CustomException(OpenChatException.DUPLICATED_NICKNAME);
5458
}
5559

@@ -127,6 +131,9 @@ private boolean checkNickname(long openChatId, String nickname) {
127131
throw new CustomException(OpenChatException.NOT_FOUND_OPEN_CHAT);
128132
}
129133
return webSocketSessions.stream()
130-
.anyMatch(webSocketSession -> webSocketSession.getAttributes().get(NICKNAME).equals(nickname));
134+
.anyMatch(webSocketSession -> webSocketSession.getAttributes()
135+
.get(NICKNAME)
136+
.equals(nickname)
137+
);
131138
}
132139
}

0 commit comments

Comments
 (0)