From 0f29d22f50d98433a7c7ebbe154e9e1870f906c2 Mon Sep 17 00:00:00 2001 From: Ashley //// Date: Sat, 20 Apr 2024 19:06:57 +0000 Subject: [PATCH] remove do --- src/libpoketube/libpoketube-core.js | 34 ++++++++--------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/src/libpoketube/libpoketube-core.js b/src/libpoketube/libpoketube-core.js index 124aee3d..353116a3 100644 --- a/src/libpoketube/libpoketube-core.js +++ b/src/libpoketube/libpoketube-core.js @@ -75,35 +75,19 @@ class InnerTubePokeVidious { * @param {Object} headers - The headers to include in the fetch request. * @returns {Promise} A promise that resolves to the text content of the response. */ - /** - * Fetch data from the specified URL with the given headers, retrying once if status code is 500. - * @param {string} url - The URL to fetch data from. - * @param {Object} headers - The headers to include in the fetch request. - * @returns {Promise} A promise that resolves to the response object. - */ async function fetchData(url, headers) { - let response; - let retry = false; - /** - * Retry fetching if status code is 500. + * @type {Response} */ - do { - try { - response = await fetch(url, { headers }); - if (response.status === 500) { - console.log("Retrying due to status 500..."); - retry = true; - } else { - retry = false; - } - } catch (error) { - console.error("Error occurred during fetch:", error); - retry = false; - } - } while (retry); + const response = await fetch(url, { headers }); - return response; + if (response.status === 500) { + // If status is 500, fetch again + console.log("Retrying due to status 500..."); + return fetchData(url, headers); + } + + return response.text(); } const { fetch } = await import("undici");