Skip to content

Commit 8f8add1

Browse files
authored
Merge pull request #26 from metaversecloud-com/dev
add catch blocks
2 parents 56e8bf1 + a6d53f5 commit 8f8add1

File tree

4 files changed

+67
-26
lines changed

4 files changed

+67
-26
lines changed

server/controllers/handleCheckpointEntered.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ export const handleCheckpointEntered = async (req, res) => {
2727
checkpointsCompleted: cachedCheckpoints,
2828
});
2929
const visitor = await Visitor.create(visitorId, urlSlug, { credentials });
30-
await visitor.fireToast({
31-
groupId: "race",
32-
title: "❌ Wrong checkpoint",
33-
text: "Oops! Go back. You missed a checkpoint!",
34-
});
30+
await visitor
31+
.fireToast({
32+
groupId: "race",
33+
title: "❌ Wrong checkpoint",
34+
text: "Oops! Go back. You missed a checkpoint!",
35+
})
36+
.catch((error) =>
37+
errorHandler({
38+
error,
39+
functionName: "handleCheckpointEntered",
40+
message: "Error firing toast",
41+
}),
42+
);
3543
return;
3644
} else {
3745
redisObj.publish(channel, {

server/controllers/handleRaceStart.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ export const handleRaceStart = async (req, res) => {
1212
redisObj.set(profileId, JSON.stringify({ 0: false }));
1313

1414
const world = World.create(urlSlug, { credentials });
15-
world.triggerActivity({ type: WorldActivityType.GAME_ON, assetId }).catch((error) => {
16-
console.error("Error triggering activity:", error);
17-
});
15+
world.triggerActivity({ type: WorldActivityType.GAME_ON, assetId }).catch((error) =>
16+
errorHandler({
17+
error,
18+
functionName: "handleRaceStart",
19+
message: "Error triggering world activity",
20+
}),
21+
);
1822

1923
// move visitor to start line asset
2024
const startCheckpoint = (

server/utils/checkpoints/checkpointEntered.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ export const checkpointEntered = async ({ checkpointNumber, currentTimestamp, cr
1313
const currentElapsedTime = !startTimestamp ? null : formatElapsedTime(currentTimestamp - startTimestamp);
1414

1515
const visitor = await Visitor.create(visitorId, urlSlug, { credentials });
16-
await visitor.fireToast({
17-
groupId: "race",
18-
title: `✅ Checkpoint ${checkpointNumber}`,
19-
text: ENCOURAGEMENT_MESSAGES[checkpointNumber % ENCOURAGEMENT_MESSAGES.length],
20-
});
16+
await visitor
17+
.fireToast({
18+
groupId: "race",
19+
title: `✅ Checkpoint ${checkpointNumber}`,
20+
text: ENCOURAGEMENT_MESSAGES[checkpointNumber % ENCOURAGEMENT_MESSAGES.length],
21+
})
22+
.catch((error) =>
23+
errorHandler({
24+
error,
25+
functionName: "checkpointEntered",
26+
message: "Error firing toast",
27+
}),
28+
);
2129

2230
await world.updateDataObject(
2331
{

server/utils/checkpoints/finishLineEntered.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,44 @@ export const finishLineEntered = async ({ credentials, currentElapsedTime, profi
2525
);
2626

2727
if (newHighscore !== highscore)
28-
world.triggerActivity({ type: WorldActivityType.GAME_HIGH_SCORE, assetId }).catch((error) => {
29-
console.error("Error triggering activity:", error);
30-
});
28+
world.triggerActivity({ type: WorldActivityType.GAME_HIGH_SCORE, assetId }).catch((error) =>
29+
errorHandler({
30+
error,
31+
functionName: "finishLineEntered",
32+
message: "Error triggering world activity",
33+
}),
34+
);
3135

3236
const visitor = await Visitor.get(visitorId, urlSlug, { credentials });
3337
const { x, y } = visitor.moveTo;
3438

35-
visitor.fireToast({
36-
groupId: "race",
37-
title: "🏁 Finish",
38-
text: `You finished the race! Your time: ${currentElapsedTime}`,
39-
});
40-
visitor.triggerParticle({
41-
name: "trophy_float",
42-
duration: 3,
43-
position: { x, y },
44-
});
39+
visitor
40+
.fireToast({
41+
groupId: "race",
42+
title: "🏁 Finish",
43+
text: `You finished the race! Your time: ${currentElapsedTime}`,
44+
})
45+
.catch((error) =>
46+
errorHandler({
47+
error,
48+
functionName: "finishLineEntered",
49+
message: "Error firing toast",
50+
}),
51+
);
52+
53+
visitor
54+
.triggerParticle({
55+
name: "trophy_float",
56+
duration: 3,
57+
position: { x, y },
58+
})
59+
.catch((error) =>
60+
errorHandler({
61+
error,
62+
functionName: "finishLineEntered",
63+
message: "Error triggering particle effects",
64+
}),
65+
);
4566

4667
return;
4768
} catch (error) {

0 commit comments

Comments
 (0)