Error response Bad gateway

Hi everyone,
I’m running my API through Cloudflare (Free plan) and everything works fine for 200 responses, which come back as JSON. However, whenever my origin returns a 4xx or 5xx, Cloudflare serves its standard HTML error page (e.g. 502 Bad Gateway) instead of passing through the JSON payload I expect.

What I’ve tried so far:

Disabled HTTP/3 (with QUIC) under Speed → Optimization → Protocol Optimization — this temporarily fixed it, but after two months the HTML errors returned.

Questions:

Is there a Free-plan setting or page rule I can use to bypass Cloudflare’s HTML error pages and preserve my JSON error responses?

Are there any known issues or workarounds around error handling on Cloudflare’s edge?

Any guidance would be greatly appreciated,
thanks in advance!
Was this page helpful?