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