Skip to content

Commit

Permalink
Refactor scanner page to handle error in puzzle exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
gnehs committed Mar 2, 2024
1 parent b4b6251 commit 30e9019
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/app/(game)/scanner/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ export default function Page() {
setShowInfo(true);
return;
}
const result = await sendPuzzle2Player(playerToken, boothToken);
if (result === puzzleSuccess) {
setInfo({ title: "已完成", msg: "恭喜獲得拼圖!!" });
} else if (result === puzzleTaken) {
setInfo({ title: "失敗", msg: "此拼圖已存在。" });
} else if (result === invalidToken) {
setInfo({ title: "失敗", msg: "請先報到。" });
try {
const result = await sendPuzzle2Player(playerToken, boothToken);
if (result === puzzleSuccess) {
setInfo({ title: "已完成", msg: "恭喜獲得拼圖!!" });
} else if (result === puzzleTaken) {
setInfo({ title: "失敗", msg: "此拼圖已存在。" });
} else if (result === invalidToken) {
setInfo({ title: "失敗", msg: "請先報到。" });
}
} catch (e) {
console.error(e);
setInfo({ title: "失敗", msg: "無法兌換此拼圖" });
}
} else {
setInfo({ title: "失敗", msg: "掃描失敗,請再試一次。" });
Expand Down

0 comments on commit 30e9019

Please sign in to comment.