mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Chore: fix fetch timeout
This commit is contained in:
parent
be434b26bd
commit
99c44b9c26
@ -27,6 +27,10 @@ const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>>
|
|||||||
console.log(key);
|
console.log(key);
|
||||||
console.time(key);
|
console.time(key);
|
||||||
|
|
||||||
|
// AbortSignal.timeout() is not supported by bun.
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timer = setTimeout(() => controller.abort(), 4000);
|
||||||
|
|
||||||
const res = await fetchWithRetry(`https://www.speedtest.net/api/js/servers?engine=js&search=${keyword}&limit=100`, {
|
const res = await fetchWithRetry(`https://www.speedtest.net/api/js/servers?engine=js&search=${keyword}&limit=100`, {
|
||||||
headers: {
|
headers: {
|
||||||
dnt: '1',
|
dnt: '1',
|
||||||
@ -44,8 +48,11 @@ const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>>
|
|||||||
retry: {
|
retry: {
|
||||||
retryOnAborted: true
|
retryOnAborted: true
|
||||||
},
|
},
|
||||||
signal: AbortSignal.timeout(4000)
|
signal: controller.signal
|
||||||
});
|
});
|
||||||
|
|
||||||
|
clearTimeout(timer);
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(`${res.statusText}\n${await res.text()}`);
|
throw new Error(`${res.statusText}\n${await res.text()}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user