Cloudflare Error 1101 "Worker threw exception" (and 1102 resource limits)

A Cloudflare Worker sits in front of the site, and it crashed. Visitors see “Error 1101: Worker threw exception”. The real error message is not on the page: it is in the Worker’s logs.

See the real error

# Stream live logs and exceptions from a deployed Worker
npx wrangler tail my-worker --format pretty

# Then reproduce the failing request in another terminal
curl -s https://app.example.com/the/failing/path -o /dev/null -w '%{http_code}\n'

Workers Logs (enable observability in the Wrangler config) keeps exceptions so you can search them later instead of only watching live.

Frequent causes of 1101

Catch it and fail gracefully

export default {
  async fetch(request, env, ctx) {
    try {
      return await handle(request, env, ctx);
    } catch (err) {
      console.error('handler failed', err && err.stack);
      return new Response('Something went wrong', { status: 500 });
    }
  },
};

For a Worker on a route in front of an origin, ctx.passThroughOnException() tells Cloudflare to send the request to the origin as if the Worker were not there when it throws. That keeps the site up while you fix the bug, but it skips any auth or rewriting the Worker does, so use it only where that is safe.

Error 1102: exceeded resource limits

Related

All Cloudflare error codes · TypeError: fetch failed · Unexpected token in JSON · Unexpected end of JSON input · JavaScript heap out of memory · Cloudflare Error 1033 · JSON formatter

Questions

What does Cloudflare error 1101 mean?

A Cloudflare Worker handling the request threw an uncaught exception or returned a rejected promise.

How do I see why my Worker threw?

Run npx wrangler tail for the Worker (or open its Logs in the dashboard), reproduce the request, and read the exception and stack trace.

What is Cloudflare error 1102?

The Worker exceeded its resource limits: usually CPU time per request, sometimes memory.

Can I make the site work while the Worker is broken?

For a route Worker in front of an origin, ctx.passThroughOnException() sends the request to the origin when the Worker throws. Only use it if skipping the Worker is safe.

Does waiting on fetch count towards CPU time?

No. CPU time counts computation, not time spent waiting for network responses.

Published .

Try it

Related guides

Newest guides