mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 22:37:56 +01:00
remove do
This commit is contained in:
parent
fd9a651682
commit
0f29d22f50
1 changed files with 9 additions and 25 deletions
|
@ -75,35 +75,19 @@ class InnerTubePokeVidious {
|
||||||
* @param {Object} headers - The headers to include in the fetch request.
|
* @param {Object} headers - The headers to include in the fetch request.
|
||||||
* @returns {Promise<string>} A promise that resolves to the text content of the response.
|
* @returns {Promise<string>} 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<Response>} A promise that resolves to the response object.
|
|
||||||
*/
|
|
||||||
async function fetchData(url, headers) {
|
async function fetchData(url, headers) {
|
||||||
let response;
|
|
||||||
let retry = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retry fetching if status code is 500.
|
* @type {Response}
|
||||||
*/
|
*/
|
||||||
do {
|
const response = await fetch(url, { headers });
|
||||||
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);
|
|
||||||
|
|
||||||
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");
|
const { fetch } = await import("undici");
|
||||||
|
|
Loading…
Reference in a new issue