3131import io .f1 .backend .domain .game .store .RoomRepository ;
3232import io .f1 .backend .domain .quiz .app .QuizService ;
3333import io .f1 .backend .domain .quiz .entity .Quiz ;
34+ import io .f1 .backend .global .exception .CustomException ;
35+ import io .f1 .backend .global .exception .errorcode .RoomErrorCode ;
3436
3537import lombok .RequiredArgsConstructor ;
3638import lombok .extern .slf4j .Slf4j ;
3739
38- import org .hibernate .boot .model .naming .IllegalIdentifierException ;
3940import org .springframework .context .ApplicationEventPublisher ;
4041import org .springframework .stereotype .Service ;
4142
@@ -91,18 +92,18 @@ public void enterRoom(RoomValidationRequest request) {
9192 Room room = findRoom (request .roomId ());
9293
9394 if (room .getState ().equals (RoomState .PLAYING )) {
94- throw new IllegalArgumentException ( "403 게임이 진행중입니다." );
95+ throw new CustomException ( RoomErrorCode . ROOM_GAME_IN_PROGRESS );
9596 }
9697
9798 int maxUserCnt = room .getRoomSetting ().maxUserCount ();
9899 int currentCnt = room .getUserIdSessionMap ().size ();
99100 if (maxUserCnt == currentCnt ) {
100- throw new IllegalArgumentException ( "403 정원이 모두 찼습니다." );
101+ throw new CustomException ( RoomErrorCode . ROOM_USER_LIMIT_REACHED );
101102 }
102103
103104 if (room .getRoomSetting ().locked ()
104105 && !room .getRoomSetting ().password ().equals (request .password ())) {
105- throw new IllegalArgumentException ( "401 비밀번호가 일치하지 않습니다." );
106+ throw new CustomException ( RoomErrorCode . WRONG_PASSWORD );
106107 }
107108
108109 room .getUserIdSessionMap ().put (getCurrentUserId (), PENDING_SESSION_ID );
@@ -201,7 +202,7 @@ private Player getRemovePlayer(Room room, String sessionId) {
201202 Player removePlayer = room .getPlayerSessionMap ().get (sessionId );
202203 if (removePlayer == null ) {
203204 room .removeUserId (getCurrentUserId ());
204- throw new IllegalIdentifierException ( "404 세션 없음 비정상적인 퇴장 요청" );
205+ throw new CustomException ( RoomErrorCode . SOCKET_SESSION_NOT_FOUND );
205206 }
206207 return removePlayer ;
207208 }
@@ -217,7 +218,7 @@ private Player createPlayer() {
217218 private Room findRoom (Long roomId ) {
218219 return roomRepository
219220 .findRoom (roomId )
220- .orElseThrow (() -> new IllegalArgumentException ( "404 존재하지 않는 방입니다." ));
221+ .orElseThrow (() -> new CustomException ( RoomErrorCode . ROOM_NOT_FOUND ));
221222 }
222223
223224 private boolean isLastPlayer (Room room , String sessionId ) {
@@ -244,9 +245,7 @@ private void changeHost(Room room, String hostSessionId) {
244245 Player nextHost =
245246 playerSessionMap .get (
246247 nextHostSessionId .orElseThrow (
247- () ->
248- new IllegalArgumentException (
249- "방장 교체 불가 - 404 해당 세션 플레이어는 존재하지않습니다." )));
248+ () -> new CustomException (RoomErrorCode .SOCKET_SESSION_NOT_FOUND )));
250249
251250 room .updateHost (nextHost );
252251 log .info ("user_id:{} 방장 변경 완료 " , nextHost .getId ());
0 commit comments