From ce1e7d847379ee6b4f732aa5e2ee5ab2188dd4fa Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 2 Mar 2023 15:05:53 +0000 Subject: [PATCH] add try catch :p --- src/libpoketube/libpoketube-core.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libpoketube/libpoketube-core.js b/src/libpoketube/libpoketube-core.js index 051d48f..4cef815 100644 --- a/src/libpoketube/libpoketube-core.js +++ b/src/libpoketube/libpoketube-core.js @@ -83,7 +83,6 @@ async function video(v) { var comments = ""; } - const urls = [ "invidious.sethforprivacy.com", "invidious.weblibre.org", @@ -94,21 +93,25 @@ async function video(v) { let vid; -for (const url of urls) { - const videoInfo = await fetch(`https://${url}/api/v1/videos/${v}`).then(res => res.text()); - vid = await getJson(videoInfo); +try { + for (const url of urls) { + const videoInfo = await fetch(`https://${url}/api/v1/videos/${v}`).then(res => res.text()); + vid = await getJson(videoInfo); - if (vid?.descriptionHtml !== "

") { - break; + if (vid?.descriptionHtml !== "

") { + break; + } } -} -if (!vid) { + if (!vid) { + // Handle error case + throw new Error('Unable to fetch video information.'); + } +} catch (error) { + console.error(error); // Handle error case } - - if (checkUnexistingObject(vid)) { var a;