🥅 Catching an error if Game Pin is invalid in join.svelte

This commit is contained in:
Mawoka
2022-06-15 17:33:26 +02:00
parent 12d9e8325a
commit 1ef0eb3a64
+15 -3
View File
@@ -44,9 +44,21 @@
return; return;
} }
let captcha_resp: string; let captcha_resp: string;
const captcha_enabled = ( const res = await fetch(`/api/v1/quiz/play/check_captcha/${game_pin}`);
await (await fetch(`/api/v1/quiz/play/check_captcha/${game_pin}`)).json() let captcha_enabled;
).enabled; if (res.status === 200) {
captcha_enabled = (await res.json()).enabled;
}
if (res.status === 404) {
alert('Game not found');
game_pin = '';
return;
}
if (res.status !== 200) {
alert('Unknown error!');
return;
}
if (captcha_enabled) { if (captcha_enabled) {
try { try {
const { response } = await hcaptcha.execute(hcaptchaWidgetID, { const { response } = await hcaptcha.execute(hcaptchaWidgetID, {