initGame() try catch
This commit is contained in:
@@ -59,39 +59,42 @@
|
|||||||
optionsAreNotSet = false;
|
optionsAreNotSet = false;
|
||||||
showWaitPage = true;
|
showWaitPage = true;
|
||||||
const matchOptions = pong.computeMatchOptions(options);
|
const matchOptions = pong.computeMatchOptions(options);
|
||||||
|
try {
|
||||||
const response = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/ticket`, {
|
const response = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/ticket`, {
|
||||||
method : "POST",
|
method : "POST",
|
||||||
headers : {'Content-Type': 'application/json'},
|
headers : {'Content-Type': 'application/json'},
|
||||||
body : JSON.stringify({
|
body : JSON.stringify({
|
||||||
playerOneUsername : options.playerOneUsername,
|
playerOneUsername : options.playerOneUsername,
|
||||||
playerTwoUsername : options.playerTwoUsername,
|
playerTwoUsername : options.playerTwoUsername,
|
||||||
gameOptions : matchOptions,
|
gameOptions : matchOptions,
|
||||||
isGameIsWithInvitation : options.isSomeoneIsInvited
|
isGameIsWithInvitation : options.isSomeoneIsInvited
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
console.log("status : " + response.status);
|
console.log("status : " + response.status);
|
||||||
const responseBody = await response.json();
|
const responseBody = await response.json();
|
||||||
const token : string = responseBody.token;
|
const token : string = responseBody.token;
|
||||||
showWaitPage = false;
|
showWaitPage = false;
|
||||||
if (response.ok && token)
|
if (response.ok && token)
|
||||||
{
|
{
|
||||||
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
|
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
|
||||||
pong.init(matchOptions, options, gameAreaId, token);
|
pong.init(matchOptions, options, gameAreaId, token);
|
||||||
hiddenGame = false;
|
hiddenGame = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log(responseBody);
|
console.log(responseBody);
|
||||||
console.log("On refuse le ticket");
|
console.log("On refuse le ticket");
|
||||||
errorMessage = responseBody.message;
|
errorMessage = responseBody.message;
|
||||||
showError = true;
|
showError = true;
|
||||||
options.reset(user.username);
|
options.reset(user.username);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
optionsAreNotSet = true;
|
optionsAreNotSet = true;
|
||||||
showError = false;
|
showError = false;
|
||||||
errorMessage = "";
|
errorMessage = "";
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user