Chore: minor changes

This commit is contained in:
SukkaW 2025-11-20 22:23:40 +08:00
parent 31fb27cc82
commit 9bc40a80b5
2 changed files with 7 additions and 21 deletions

View File

@ -8,14 +8,9 @@ import { AdGuardFilterIgnoreUnsupportedLinesStream } from './parse-filter/filter
import { appendArrayInPlace } from 'foxts/append-array-in-place';
import { newQueue } from '@henrygd/queue';
import { AbortError } from 'foxts/abort-error';
// eslint-disable-next-line sukka/unicorn/custom-error-definition -- typescript is better
class CustomAbortError extends Error {
public readonly name = 'AbortError';
public readonly digest = 'AbortError';
}
const reusedCustomAbortError = new CustomAbortError();
const reusedCustomAbortError = new AbortError();
const queue = newQueue(16);

View File

@ -18,6 +18,7 @@ import { inspect } from 'node:util';
import path from 'node:path';
import fs from 'node:fs';
import { CACHE_DIR } from '../constants/dir';
import { isAbortErrorLike } from 'foxts/abort-error';
if (!fs.existsSync(CACHE_DIR)) {
fs.mkdirSync(CACHE_DIR, { recursive: true });
@ -166,13 +167,8 @@ export async function $$fetch(url: string, init: RequestInit = defaultRequestIni
return res;
} catch (err: unknown) {
if (typeof err === 'object' && err !== null && 'name' in err) {
if ((
err.name === 'AbortError'
|| ('digest' in err && err.digest === 'AbortError')
)) {
console.log(picocolors.gray('[fetch abort]'), url);
}
if (isAbortErrorLike(err)) {
console.log(picocolors.gray('[fetch abort]'), url);
} else {
console.log(picocolors.gray('[fetch fail]'), url, { name: (err as any).name }, err);
}
@ -195,13 +191,8 @@ export async function requestWithLog(url: string, opt?: Parameters<typeof undici
return res;
} catch (err: unknown) {
if (typeof err === 'object' && err !== null && 'name' in err) {
if ((
err.name === 'AbortError'
|| ('digest' in err && err.digest === 'AbortError')
)) {
console.log(picocolors.gray('[fetch abort]'), url);
}
if (isAbortErrorLike(err)) {
console.log(picocolors.gray('[fetch abort]'), url);
} else {
console.log(picocolors.gray('[fetch fail]'), url, { name: (err as any).name }, err);
}