mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
fix:抽卡记录请求
This commit is contained in:
parent
c059050b8b
commit
cf4c27da44
2 changed files with 21 additions and 3 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue