rsnext/errors/invalid-api-status-body.mdx
Michael Novotny fe797c1074
Updates Mozilla links to not include language preference (#55326)
Internal suggestion to remove `en-US` from Mozilla urls since MDN is
available in multiple languages nowadays it will automatically redirect
to the viewer’s language preference.

Closes
[DX-2076](https://linear.app/vercel/issue/DX-2076/make-external-mozilla-links-language-agnostic-in-nextjs-docs)
2023-09-13 11:06:29 -05:00

34 lines
869 B
Text

---
title: Invalid API Route Status/Body Response
---
## Why This Error Occurred
In one of your API routes a 204 or 304 status code was used as well as sending a response body.
This is invalid as a 204 or 304 status code dictates no response body should be present.
## Possible Ways to Fix It
Send an empty body when using a 204 or 304 status code or use a different status code while sending a response body.
Before
```js filename="pages/api/example.js"
export default function handler(req, res) {
res.status(204).send('invalid body')
}
```
After
```js filename="pages/api/example.js"
export default function handler(req, res) {
res.status(204).end()
}
```
## Useful Links
- [204 status code documentation](https://developer.mozilla.org/docs/Web/HTTP/Status/204)
- [304 status code documentation](https://developer.mozilla.org/docs/Web/HTTP/Status/304)