mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Chore: minor changes
This commit is contained in:
parent
31fb27cc82
commit
9bc40a80b5
@ -8,14 +8,9 @@ import { AdGuardFilterIgnoreUnsupportedLinesStream } from './parse-filter/filter
|
|||||||
import { appendArrayInPlace } from 'foxts/append-array-in-place';
|
import { appendArrayInPlace } from 'foxts/append-array-in-place';
|
||||||
|
|
||||||
import { newQueue } from '@henrygd/queue';
|
import { newQueue } from '@henrygd/queue';
|
||||||
|
import { AbortError } from 'foxts/abort-error';
|
||||||
|
|
||||||
// eslint-disable-next-line sukka/unicorn/custom-error-definition -- typescript is better
|
const reusedCustomAbortError = new AbortError();
|
||||||
class CustomAbortError extends Error {
|
|
||||||
public readonly name = 'AbortError';
|
|
||||||
public readonly digest = 'AbortError';
|
|
||||||
}
|
|
||||||
|
|
||||||
const reusedCustomAbortError = new CustomAbortError();
|
|
||||||
|
|
||||||
const queue = newQueue(16);
|
const queue = newQueue(16);
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import { inspect } from 'node:util';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { CACHE_DIR } from '../constants/dir';
|
import { CACHE_DIR } from '../constants/dir';
|
||||||
|
import { isAbortErrorLike } from 'foxts/abort-error';
|
||||||
|
|
||||||
if (!fs.existsSync(CACHE_DIR)) {
|
if (!fs.existsSync(CACHE_DIR)) {
|
||||||
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
||||||
@ -166,13 +167,8 @@ export async function $$fetch(url: string, init: RequestInit = defaultRequestIni
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
if (typeof err === 'object' && err !== null && 'name' in err) {
|
if (isAbortErrorLike(err)) {
|
||||||
if ((
|
console.log(picocolors.gray('[fetch abort]'), url);
|
||||||
err.name === 'AbortError'
|
|
||||||
|| ('digest' in err && err.digest === 'AbortError')
|
|
||||||
)) {
|
|
||||||
console.log(picocolors.gray('[fetch abort]'), url);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
console.log(picocolors.gray('[fetch fail]'), url, { name: (err as any).name }, err);
|
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;
|
return res;
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
if (typeof err === 'object' && err !== null && 'name' in err) {
|
if (isAbortErrorLike(err)) {
|
||||||
if ((
|
console.log(picocolors.gray('[fetch abort]'), url);
|
||||||
err.name === 'AbortError'
|
|
||||||
|| ('digest' in err && err.digest === 'AbortError')
|
|
||||||
)) {
|
|
||||||
console.log(picocolors.gray('[fetch abort]'), url);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
console.log(picocolors.gray('[fetch fail]'), url, { name: (err as any).name }, err);
|
console.log(picocolors.gray('[fetch fail]'), url, { name: (err as any).name }, err);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user