Skip to content

Commit 9f1f689

Browse files
handleStartGame에 오류 처리 추가
1 parent 3ccbb21 commit 9f1f689

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

src/app/hooks/useHandler.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,20 @@ const useHandler = () => {
7474
};
7575

7676
const handleStartGame = async (invitationCode: InvitationCode, players: Players) => {
77-
const gameDocRef = ref(db, 'games/' + invitationCode);
78-
await runTransaction(gameDocRef, (currentData: GameData) => {
79-
if (!currentData) {
80-
const newGame = createNewGame(invitationCode, players);
81-
return newGame;
82-
}
83-
});
84-
const roomDocRef = ref(db, 'rooms/' + invitationCode);
85-
await runTransaction(roomDocRef, (currentData: RoomData) => {
86-
if (!currentData) return undefined;
87-
return null;
88-
});
77+
try {
78+
const gameDocRef = ref(db, 'games/' + invitationCode);
79+
await runTransaction(gameDocRef, (currentData: GameData) => {
80+
if (currentData) return;
81+
return createNewGame(invitationCode, players);
82+
});
83+
84+
const roomDocRef = ref(db, 'rooms/' + invitationCode);
85+
await update(roomDocRef, { status: 'playing' });
86+
87+
} catch (error) {
88+
console.error("게임을 시작하는 중 오류가 발생했습니다:", error);
89+
alert("오류가 발생하여 게임을 시작할 수 없습니다.");
90+
}
8991
};
9092

9193
const handleAccuse = async (

0 commit comments

Comments
 (0)