Chore: minor changes
Some checks are pending
Build / Build (push) Waiting to run
Build / Deploy to Cloudflare Pages (push) Blocked by required conditions
Build / Deploy to GitHub and GitLab (push) Blocked by required conditions

This commit is contained in:
SukkaW
2025-01-22 20:49:56 +08:00
parent 623e45bba6
commit 3c2b49df76
8 changed files with 66 additions and 203 deletions

View File

@@ -11,23 +11,7 @@ export class CustomAbortError extends Error {
public readonly digest = 'AbortError';
}
export class Custom304NotModifiedError extends Error {
public readonly name = 'Custom304NotModifiedError';
public readonly digest = 'Custom304NotModifiedError';
constructor(public readonly url: string, public readonly data: string) {
super('304 Not Modified');
}
}
export class CustomNoETagFallbackError extends Error {
public readonly name = 'CustomNoETagFallbackError';
public readonly digest = 'CustomNoETagFallbackError';
constructor(public readonly data: string) {
super('No ETag Fallback');
}
}
const reusedCustomAbortError = new CustomAbortError();
export async function fetchAssets(url: string, fallbackUrls: null | undefined | string[] | readonly string[], processLine = false) {
const controller = new AbortController();
@@ -39,12 +23,12 @@ export async function fetchAssets(url: string, fallbackUrls: null | undefined |
await waitWithAbort(50 + (index + 1) * 100, controller.signal);
} catch {
console.log(picocolors.gray('[fetch cancelled early]'), picocolors.gray(url));
throw new CustomAbortError();
throw reusedCustomAbortError;
}
}
if (controller.signal.aborted) {
console.log(picocolors.gray('[fetch cancelled]'), picocolors.gray(url));
throw new CustomAbortError();
throw reusedCustomAbortError;
}
const res = await $$fetch(url, { signal: controller.signal, ...defaultRequestInit });