From 4a2d836cda60651893c65fc7c47eba4a1a7bfe58 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sat, 11 Mar 2023 16:03:14 +0000 Subject: [PATCH] add try catch :p --- src/libpoketube/libpoketube-core.js | 77 ++++++++++++++++------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/src/libpoketube/libpoketube-core.js b/src/libpoketube/libpoketube-core.js index a74a3b7e..cc887739 100644 --- a/src/libpoketube/libpoketube-core.js +++ b/src/libpoketube/libpoketube-core.js @@ -86,18 +86,19 @@ async function video(v) { ); var comments = await getJson(inv_comments); - } catch { + } catch (error) { + console.error("Error getting comments", error); var comments = ""; } let vid; - try { - const videoInfo = await fetch(`${config.invapi}/videos/${v}`).then(res => res.text()); - vid = await getJson(videoInfo); - } catch (error) { - - } + try { + const videoInfo = await fetch(`${config.invapi}/videos/${v}`).then(res => res.text()); + vid = await getJson(videoInfo); + } catch (error) { + console.error("Error getting video info", error); + } if (!vid) { @@ -113,7 +114,8 @@ async function video(v) { ) .then((res) => res.text()) .then((xml) => getJson(toJson(xml))); - } catch { + } catch (error) { + console.error("Error getting channel info", error); var a = ""; } @@ -128,33 +130,40 @@ async function video(v) { const data = await fetcher(v); const nightlyJsonData = getJson(nightlyRes); - const video = await fetch(`${config.tubeApi}video?v=${v}`) - .then((res) => res.text()) - .then((xml) => getJson(toJson(xml))) - .catch(" ") - - - // Store result in cache - cache[v] = { - result: { - json: data?.video?.Player, - video, - vid, - comments, - engagement: data.engagement, - wiki: summary, - desc: desc, - color: await getColors( - `https://i.ytimg.com/vi/${v}/hqdefault.jpg?sqp=${sqp}` - ).then((colors) => colors[0].hex()), - color2: await getColors( - `https://i.ytimg.com/vi/${v}/hqdefault.jpg?sqp=${sqp}` - ).then((colors) => colors[1].hex()), - }, - timestamp: Date.now() - }; - return cache[v].result; + try { + const video = await fetch(`${config.tubeApi}video?v=${v}`) + .then((res) => res.text()) + .then((xml) => getJson(toJson(xml))) + .catch(error => { + console.error("Error getting video", error); + return " "; + }); + + // Store result in cache + cache[v] = { + result: { + json: data?.video?.Player, + video, + vid, + comments, + engagement: data.engagement, + wiki: summary, + desc: desc, + color: await getColors( + `https://i.ytimg.com/vi/${v}/hqdefault.jpg?sqp=${sqp}` + ).then((colors) => colors[0].hex()), + color2: await getColors( + `https://i.ytimg.com/vi/${v}/hqdefault.jpg?sqp=${sqp}` + ).then((colors) => colors[1].hex()), + }, + timestamp: Date.now() + }; + + return cache[v].result; + } catch (error) { + console.error("Error getting video", error); + } } }