( url: string, cf?: CloudflareCacheOptions, )
| 44 | * upstream failures. |
| 45 | */ |
| 46 | const 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. */ |
| 67 | const fetchBinaryBytes = async (url: string): Promise<Uint8Array> => |
no test coverage detected