Response with status 400 from fetch call in worker responds as 520 without content


We have build a worker script for requesting shipment labels from a carrier company API.

We transform our standard shipment JSON format to the specific carrier JSON and then use fetch call to POST the JSON to the carrier API.

At the carrier system there are some validations, like “invalid zipcode”, “country code missing”, etc.
When they detect this kind of data errors, they respond with status 400 and send a neat JSON containing the information about what’s wrong.

If I call their API from Postman I see this status 400 and the error message.

But if I do exactly the same request from within worker with fetch, I get a response status 520 without any headers or response content.

It seems the Cloudflare system blocks this 400 response. How can I get the original status and response content in my worker?