error handling
This commit is contained in:
parent
b021ed90ec
commit
f5ded75323
2 changed files with 14 additions and 0 deletions
|
@ -27,6 +27,10 @@
|
||||||
const lastId = await result.text();
|
const lastId = await result.text();
|
||||||
|
|
||||||
const currentResult = await fetch("grid.php");
|
const currentResult = await fetch("grid.php");
|
||||||
|
if (!currentResult.ok) {
|
||||||
|
alert(currentResult.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const current = await currentResult.json();
|
const current = await currentResult.json();
|
||||||
|
|
||||||
let choosing;
|
let choosing;
|
||||||
|
@ -65,15 +69,21 @@
|
||||||
|
|
||||||
async function random() {
|
async function random() {
|
||||||
const currentResult = await fetch("grid.php");
|
const currentResult = await fetch("grid.php");
|
||||||
|
if (!currentResult.ok) {
|
||||||
|
alert(currentResult.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const current = await currentResult.json();
|
const current = await currentResult.json();
|
||||||
|
|
||||||
const audios = current.filter((link) => link.audio);
|
const audios = current.filter((link) => link.audio);
|
||||||
if (!audios.length) {
|
if (!audios.length) {
|
||||||
alert(`Looks like there's no audios yet. Come back later!`);
|
alert(`Looks like there's no audios yet. Come back later!`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const videos = current.filter((link) => link.video);
|
const videos = current.filter((link) => link.video);
|
||||||
if (!videos.length) {
|
if (!videos.length) {
|
||||||
alert(`Looks like there's no videos yet. Come back later!`);
|
alert(`Looks like there's no videos yet. Come back later!`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoId = videos[Math.floor(Math.random() * videos.length)].id;
|
const videoId = videos[Math.floor(Math.random() * videos.length)].id;
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
||||||
|
|
||||||
const currentResult = await fetch("grid.php");
|
const currentResult = await fetch("grid.php");
|
||||||
|
if (!currentResult.ok) {
|
||||||
|
alert(currentResult.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const current = await currentResult.json();
|
const current = await currentResult.json();
|
||||||
videoUrl = current.find((link) => link.id == videoId).url;
|
videoUrl = current.find((link) => link.id == videoId).url;
|
||||||
audioUrl = current.find((link) => link.id == audioId).url;
|
audioUrl = current.find((link) => link.id == audioId).url;
|
||||||
|
|
Loading…
Reference in a new issue