Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tjenkinson/53b5724bf8112487f6bd797368e02b56 to your computer and use it in GitHub Desktop.
Save tjenkinson/53b5724bf8112487f6bd797368e02b56 to your computer and use it in GitHub Desktop.
// workaround for https://github.com/cloudflare/workerd/issues/698
const originalFetch = globalThis.fetch;
globalThis.fetch = async function (...args) {
try {
return await originalFetch.apply(this, args);
} catch (e) {
if (!args[1] || typeof args[1] !== 'object') throw e;
const unimplementedCacheError =
e && typeof e === 'object' && 'message' in e && e.message === "The 'cache' field on 'RequestInitializerDict' is not implemented.";
if (!unimplementedCacheError) throw e;
const newOpts = { ...args[1] };
delete newOpts.cache;
return originalFetch.apply(this, [args[0], newOpts]);
}
};
@GaoangLiu
Copy link

Thanks, my friend, this workaround fixed my cloudflare worker error. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment