Common Errors
Common Errors🙋♀️
HLP creates new incentive for players to engage in your game, but it also requires additional testing to ensure a great experience for the Player.
There are a few commong test scenarios that you should test in your game. These errors will occur when trying to submit a play (either by using .play
in the Typescript SDK or calling the Play endpoint for manual API integration) They are:
- The user has not connected a wallet.
- The user does not have enough funds to play the game at the payment tier selected.
- Haste API 500 error
Once you have written your error handling code (see below) you can test these scenarios manually.
- Login to your account and disconnect your wallet under My Account / Wallet in the Haste Arcade.
- You can change your spendable balance in Handcash to 0 to simulate having no funds.
- Manually throw an error in your code right after call to
.play
to simulate a 500 from the Haste API.
The following code snippet demonstrates a potential error handling strategy for backend and frontend code. The frontend code is based on a React frontend that is utilizing hooks.
Server Side Error Handling
ServerSide.ts
try {
// Haste Service is simply a wrapper around the Typescript SDK, which is recommended.
await this.hasteService.play(playerId, leaderboardId);
} catch (err: unknown) {
const realError = err as Error;
let message =
"An error occurred while trying to start the game. Please try again later. You will not be charged.";
if (realError.message.includes("validate their email")) {
message =
"Please verify your account via email. Otherwise contact support.";
} else if (realError.message.includes("connect a wallet")) {
message = "Please connect your wallet in the Haste Arcade.";
} else if (realError.message.includes("funds")) {
message =
"Please go to your handcash wallet and adjust your spendable balance.";
}
throw new BadRequestError(message);
}
Frontend Error Handling
PlayPage.tsx
<Button
onClick={async () => {
try {
const response = await axios.post<PlayResult>(
gameServerPlayUrl, // the url of your game server's play endpoint
{ leaderboardId: selectedPaymentTier },
{
headers: {
Authorization: `Bearer ${bearerToken}`, // this bearer token would include the player id which can be decoded server side from the JWT
},
}
);
} catch (err: any) {
setError(err.response.data.message);
}
}}
/>