mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Refactor: replace fetch with undici.request
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import picocolors from 'picocolors';
|
||||
import { defaultRequestInit, fetchWithLog, ResponseError } from './fetch-retry';
|
||||
import { defaultRequestInit, requestWithLog, UndiciResponseError } from './fetch-retry';
|
||||
import { setTimeout } from 'node:timers/promises';
|
||||
|
||||
// eslint-disable-next-line sukka/unicorn/custom-error-definition -- typescript is better
|
||||
@@ -59,11 +59,11 @@ export async function fetchAssetsWith304(url: string, fallbackUrls: string[] | r
|
||||
console.log(picocolors.gray('[fetch cancelled]'), picocolors.gray(url));
|
||||
throw new CustomAbortError();
|
||||
}
|
||||
const res = await fetchWithLog(url, { signal: controller.signal, ...defaultRequestInit });
|
||||
const text = await res.text();
|
||||
const res = await requestWithLog(url, { signal: controller.signal, ...defaultRequestInit });
|
||||
const text = await res.body.text();
|
||||
|
||||
if (text.length < 2) {
|
||||
throw new ResponseError(res);
|
||||
throw new UndiciResponseError(res, url);
|
||||
}
|
||||
|
||||
controller.abort();
|
||||
|
||||
Reference in New Issue
Block a user