0

The API response body is missing when the status code is not 200. I've encounter the issue on production (Azure) only. It works fine on local machine

I've tried and able to reproduce it on a simple api as follows:

router.get('/testJsonResp', (req, res) => {
    res.status(400).json({ test: 'testResp' });
});

when I read the response text, it returned me "Bad Request"

let resp = await fetch(...);
await resp.text();

Same goes with postman as well.

Anyone have any idea what went wrong?

Scott
  • 54
  • 5
  • You should use `res.send(data)` instead of `res.json(data)` in the server. – Ktoxcon Apr 05 '21 at 16:24
  • I've tried using .send, but it still produce the same result. Any possibility it's due to IIS? – Scott Apr 05 '21 at 16:49
  • Found the solution, It seems like iisnode override my error message https://stackoverflow.com/a/15145477/6728946 – Scott Apr 05 '21 at 16:55

1 Answers1

1

Add <httpErrors existingResponse="PassThrough" /> under <system.webServer> in web.config solved the issue.

Scott
  • 54
  • 5