From 2ae3575c879f70d3b9384c7a427860119a285da9 Mon Sep 17 00:00:00 2001 From: ashley Date: Sun, 21 Sep 2025 11:05:54 +0200 Subject: [PATCH] =?UTF-8?q?retry=20indefinitely=20until=20the=20server=20d?= =?UTF-8?q?oesn=E2=80=99t=20return=20a=20500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libpoketube/libpoketube-core.js | 62 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/libpoketube/libpoketube-core.js b/src/libpoketube/libpoketube-core.js index 5b774bd1..3bf85bec 100644 --- a/src/libpoketube/libpoketube-core.js +++ b/src/libpoketube/libpoketube-core.js @@ -58,39 +58,41 @@ class InnerTubePokeVidious { "User-Agent": this.useragent, }; - const fetchWithRetry = async (url, options = {}, retries = 6) => { - let lastError; - for (let attempt = 0; attempt < retries; attempt++) { - try { - const res = await fetch(url, { - ...options, - headers: { - ...options.headers, - ...headers, - }, - }); +const fetchWithRetry = async (url, options = {}) => { + let attempt = 0; - if (res.ok) { - return res; - } + while (true) { + try { + const res = await fetch(url, { + ...options, + headers: { + ...options.headers, + ...headers, + }, + }); - if ((res.status >= 500 || res.status === 429) && attempt < retries - 1) { - this.initError(`Retrying fetch for ${url}`, res.status); - continue; - } - - return res; - } catch (err) { - lastError = err; - this.initError(`Fetch error for ${url}`, err); - if (attempt < retries - 1) { - continue; - } else { - throw lastError; - } - } + if (res.ok) { + return res; } - }; + + // If status is 500 or 429, keep retrying forever + if (res.status >= 500 || res.status === 429) { + this?.initError?.(`Retrying fetch for ${url}`, res.status); + attempt++; + continue; + } + + // If other non-OK responses, just return it + return res; + } catch (err) { + this?.initError?.(`Fetch error for ${url}`, err); + attempt++; + // retry forever on network/other errors + continue; + } + } +}; + try { const [invComments, videoInfo] = await Promise.all([