500 error when fetching URL within worker

I am trying to add authentication to some URLs via a Cloudflare Worker, but the problem I run into is once I configure the Worker on a route it starts returning a 500 error. I’ve reduced the code down to the simplest replication I can find, as follows:

addEventListener("fetch", (event) => {
  event.respondWith(
    handleRequest(event.request).catch(
      (err) => new Response(err.stack, { status: 500 })
    )
  );
});

async function handleRequest(request) {
  return fetch(request);
}

Yes, this code does basically nothing. But it results in an error. If I delete the route and try to load the URL, the underlying resource is downloaded OK.

More details about the rest of the setup:

  • My sub-domain is created as a CNAME record in Cloudflare and has proxying enabled.
  • The target of the proxied subdomain is the URL of an Azure storage container (loading it directly works fine).
  • The route doesn’t contain any wildcards it is just subdomain(dot)domain(dot)com/filename.ext.

Many of the example Workers provided in the Cloudflare documentation use fetch(request), so I expect this code should have any issues and I wonder if there is an issue somewhere else in how this is configured that is causing the issue.