Skip to content

fix(hono): return 204 for void handler results instead of crashing#108

Merged
dgellow merged 1 commit intomainfrom
sam/fix-hono-plugin
Feb 24, 2026
Merged

fix(hono): return 204 for void handler results instead of crashing#108
dgellow merged 1 commit intomainfrom
sam/fix-hono-plugin

Conversation

@dgellow
Copy link
Member

@dgellow dgellow commented Feb 24, 2026

Hono 4.12.1 added a fast path in Context.json() that uses the static Response.json() method. Unlike the previous JSON.stringify() + new Response() path, Response.json(undefined) throws TypeError: Value is not JSON serializable.

Any stl endpoint handler that returns void (e.g. webhook handlers that do work but have no meaningful response) hits c.json(undefined) in the plugin and crashes with a 500 in production on Hono >= 4.12.

Return a 204 No Content when the handler result is undefined, which is the correct HTTP semantic for "request succeeded, no body".

It's fixed in hono 4.12.2 as far as I can tell

@dgellow dgellow force-pushed the sam/fix-hono-plugin branch 2 times, most recently from 2dd0b25 to 211d4ef Compare February 24, 2026 13:46
Hono 4.12 added a fast path in `Context.json()` that uses the static
`Response.json()` method. Unlike the previous `JSON.stringify()` +
`new Response()` path, `Response.json(undefined)` throws
`TypeError: Value is not JSON serializable`.

Any stl endpoint handler that returns void (e.g. webhook handlers that
do work but have no meaningful response) hits `c.json(undefined)` in
the plugin and crashes with a 500 in production on Hono >= 4.12.

Return a 204 No Content when the handler result is `undefined`, which
is the correct HTTP semantic for "request succeeded, no body".
@dgellow dgellow force-pushed the sam/fix-hono-plugin branch from 211d4ef to 3fa2af2 Compare February 24, 2026 13:50
@dgellow dgellow merged commit d75f36b into main Feb 24, 2026
1 check passed
@dgellow dgellow deleted the sam/fix-hono-plugin branch February 24, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant