MCPcopy Create free account
hub / github.com/fontsource/fontsource / fetchWithCache

Function fetchWithCache

api/shared/upstream.ts:46–64  ·  view source on GitHub ↗
(
	url: string,
	cf?: CloudflareCacheOptions,
)

Source from the content-addressed store, hash-verified

44 * upstream failures.
45 */
46const fetchWithCache = async (
47 url: string,
48 cf?: CloudflareCacheOptions,
49): Promise<Response> => {
50 const init = cf ? ({ cf } as RequestInit) : undefined;
51 const response = await fetch(url, init);
52
53 if (!response.ok) {
54 if (response.status === 404) {
55 throw new UpstreamNotFoundError(url);
56 }
57
58 throw new HTTPException(502, {
59 message: `Bad Gateway. Failed to fetch ${url}: ${response.status}`,
60 });
61 }
62
63 return response;
64};
65
66/** Fetches an upstream binary with asset-specific cache policy. */
67const fetchBinaryBytes = async (url: string): Promise<Uint8Array> =>

Callers 4

fetchBinaryBytesFunction · 0.85
fetchCachedJsonFunction · 0.85
fetchPackageTarballFunction · 0.85

Calls 1

fetchFunction · 0.85

Tested by

no test coverage detected