Skip to content
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

A single c.body() return in a handler overrides all other returns #3798

Closed
cybercoder-naj opened this issue Jan 4, 2025 · 2 comments · Fixed by #3800
Closed

A single c.body() return in a handler overrides all other returns #3798

cybercoder-naj opened this issue Jan 4, 2025 · 2 comments · Fixed by #3800
Labels

Comments

@cybercoder-naj
Copy link

cybercoder-naj commented Jan 4, 2025

What version of Hono are you using?

4.5.5

What runtime/platform is your app running on? (with version if possible)

Bun 1.1.38

What steps can reproduce the bug?

import { Hono } from 'hono';

const app = new Hono()
  .get('/hello', async c => {
    const time = Date.now();

    if (isWinter(time))
      return c.text('You cannot use this winter', 400)
    if (isSummer(time))
      return c.text('You cannot use this summer', 400)

    return c.body(null, 204) 
  })

Why use body in the first place? Because 204 is a ContentlessStatusCode and c.text or c.json no longer accept this as a valid status code.

What is the expected behavior?

The return type of app.hello.$get() should be Promise<ClientResponse<'You cannot use this winter', 400, 'text'> | ClientResponse<'You cannot use this summer', 400, 'text'> | ClientResponse<null, 204, string>>

What do you see instead?

The return type of app.hello.$get() is actually Promise<ClientResponse<{}, StatusCode, string>>

Additional information

No response

@lewisedc
Copy link

lewisedc commented Jan 4, 2025

I'm also running into this issue.

I believe the Hono version however should be 4.6.15 which was when the StatusCode change was implemented.

@askorupskyy
Copy link
Contributor

Hey guys, thanks for bringing this up. I did some investigation and I think I know where this could be coming from. Let me see what I can do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants