Workers recently receiving error code 1021 when fetching 3rd party website?

In the past 3 days, my worker script started to receive “error code: 1021” as fetch response content recently.

In my worker script, I fetched some content from another website with cookies. It seems recently headers.get(“Set-Cookie”) no longer works as well?

  const loginRequest = new Request(url, {
    body: rq,
    method: "POST",
    redirect: "follow",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    cf: {
      apps: false,
      mirage: false,
      scrapeShield: false,
    },
  });
  const resp = await fetch(loginRequest);

Preview build doesn’t have this issue. Only the production build has this issue.

I also cannot find any documentation on error 1021.

someone from discord chat posted the same issue:

sorry if this is the wrong place to ask, i’m having some issues w a cf worker domain. I’ve got a worker that redirects traffic to a server after injecting headers into the request, and its published and works from the workers.dev endpoint. I do have an A record listed for api.mydomain.com pointed at 1.2.3.4 and a route for api.mydomain.com/* and from what I read that should work but when I call the worker from the custom domain I get a 1021 error about my server mybackend.com but don’t get that error when calling from the workers.dev endpoint. Any help is appreciated thanks.

Again, someone in the discord chat pointed me out, and their solution worked for me.

In case someone having the same issue, please remove the CNAME and set up a page rule to redirect your {domain}.com to www.{domain}.com as a workaround.

og_jamesc: This issue could be because i did something dumb, but: When you set up CF pages and use your main domain as a custom domain for CF Pages, AND you use your main domain with workers and set up subdomain for your worker scripts, it wont break workers IE, it wont stop you from requesting your worker but it broke some fetch() calls to external sites such as GitHub, i was getting the http code of 409. removing my main domain name from CF Pages fixed this issue. Im sure i can repeat this issue if needed. Just thought id put this here if someone else has a similar issue.

1 Like