-
-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot response HTTP code 204 when using context.json()
#1518
Comments
When status code is 204, Response can't contain any content. Body is empty always. |
HTTP Status 204 signifies that there is no content in the response body. Given your code, what you want to use is status 404 instead, which is usually used when you cannot find a record, where you can include a body. |
Is this problem resolved? If you wan to return 204 with no body, you can return |
Closing. If you have any problems, please reopen |
@yusukebe just encountered this. While it's an easy fix, this was missed in one of my PRs and caused a few errors in prod. Do you think it could be a good idea to omit the |
Yes @askorupskyy. |
What I had in mind is doing something like json: JSONRespond = <
T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue,
U extends Exclude<StatusCode, '204'> = Exclude<StatusCode, '204'>
> This way TypeScript would let us know if we're trying to do something that would cause errors in runtime |
Interesting idea |
Throwing a TypeScript error if the Response has a status code that can't have a |
@yusukebe i will make a pr for this soon |
That is correct. |
What version of Hono are you using?
3.7.2
What runtime/platform is your app running on?
Node
What steps can reproduce the bug?
What is the expected behavior?
I expected this implemented code should response 204 (No content) data
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: