TypeError: Response constructor: Invalid response status code 204

Hi, I seem to be getting the following error on the latest version of Hono when using any 2XX status from 204 and above. It is ocurring when I set the context status using c.status(2XX) before I return a JSON response.
9 Replies
kapitalist (Назар)
Did you try to:
return c.json(yourJson, 204}
return c.json(yourJson, 204}
kylemandell
kylemandellOP6mo ago
Yup - same error occurs
kapitalist (Назар)
Do you use it with node, bun, deno?
kylemandell
kylemandellOP6mo ago
node
kapitalist (Назар)
Can you post code snippet?
kylemandell
kylemandellOP6mo ago
I don't have much else to share, I'm just trying to return c.json({}, 204) and still get that error This is on Hono 4.4.5, but I don't believe it was an issue when I was on 4.3.9 Actually, just gone back to 4.3.9 and it seems to be happening there too
Aditya Mathur
Aditya Mathur6mo ago
This is not an error, this is by design. I believe you should only be getting errors for status code 204 and 205. If you check the MDN docs for these status code (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204), it will tell you that these codes don't expect content to be with them. And you can send them in other API frameworks (maybe) but the browsers rejects them. So hono basically gives you an error if you try to do this.
Aditya Mathur
Aditya Mathur6mo ago
I have created an issue from this to have better error messages to easily debug issues like these in the future - https://github.com/honojs/hono/issues/2971
GitHub
feat: better error messages for status code errors · Issue #2971 · ...
What is the feature you are proposing? There are quite some issues devs are having in Discord when Hono gives errors for status codes. E.g. - returning JSON data with status codes 204 and 205. Here...
kylemandell
kylemandellOP6mo ago
Ahh - yes I realised that a small change elsewhere meant the body was being passed as {} rather than undefined. Better error messages in this case sound good to me!
Want results from more Discord servers?
Add your server