fix:抽卡记录请求

This commit is contained in:
别调P 2024-07-20 01:41:29 +08:00
parent c059050b8b
commit cf4c27da44
2 changed files with 21 additions and 3 deletions

View file

@ -1,5 +1,6 @@
import http from 'http';
import https from 'https';
import fetch from 'node-fetch';
export async function checkLatency(url) {
let request = http;
if (url.startsWith('https')) {
@ -46,3 +47,20 @@ export function getQueryVariable(url, variable) {
return null;
}
}
export async function fetchWithRetry(url, options, retry = 3) {
let err;
const _fetch = async (url, options, retryCount = 0) => {
if (retryCount > retry) {
throw new Error('Retry limit reached', err);
}
try {
return await fetch(url, options);
} catch (error) {
logger.debug(`Fetch error: ${error.message}`);
err = error;
return _fetch(url, options, retryCount + 1);
}
};
return _fetch(url, options);
}