fix(transformers)!: answer 204 when a handler returns undefined (GitHub #38) #172

Merged
chrnx merged 1 commits from fix/undefined-return-204 into develop 2026-10-25 03:51:59 +00:00
Owner

JsonTransformer passed the handler's value to JSON.stringify, which
returns undefined for undefined, while TransformerFn promises a string
body. The Node server wrote that as an empty 200 with content-type
application/json; the fetch adapter's toBodyInit read body.buffer on
it and threw, so Deno, Bun and the edge answered 500 for a handler with
no return.

JsonTransformer now returns status 204 and an empty body (no headers)
for undefined. outcomeToResponse already sends a null body for 204 and
the Node server ends with the empty string, so all four runtimes give
the same answer. null is a JSON value and still renders as 200 null.
Routes with their own @Transformer are unchanged.

BREAKING CHANGE: a handler with no return value now answers 204 instead
of an empty 200 on Node (and instead of 500 elsewhere). Return a value
to keep a 200.

test/undefined-return.test.ts covers app.fetch and the Node server
(both fail without the fix) and pins null to 200.

JsonTransformer passed the handler's value to JSON.stringify, which returns undefined for undefined, while TransformerFn promises a string body. The Node server wrote that as an empty 200 with content-type application/json; the fetch adapter's toBodyInit read `body.buffer` on it and threw, so Deno, Bun and the edge answered 500 for a handler with no `return`. JsonTransformer now returns status 204 and an empty body (no headers) for undefined. outcomeToResponse already sends a null body for 204 and the Node server ends with the empty string, so all four runtimes give the same answer. null is a JSON value and still renders as 200 `null`. Routes with their own @Transformer are unchanged. BREAKING CHANGE: a handler with no return value now answers 204 instead of an empty 200 on Node (and instead of 500 elsewhere). Return a value to keep a 200. test/undefined-return.test.ts covers app.fetch and the Node server (both fail without the fix) and pins null to 200.
chrnx added 1 commit 2026-10-25 03:49:50 +00:00
fix(transformers)!: answer 204 when a handler returns undefined (GitHub #38)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 21s
CI / runtimes (deno) (pull_request) Successful in 33s
40702aef2a
JsonTransformer passed the handler's value to JSON.stringify, which
returns undefined for undefined, while TransformerFn promises a string
body. The Node server wrote that as an empty 200 with content-type
application/json; the fetch adapter's toBodyInit read `body.buffer` on
it and threw, so Deno, Bun and the edge answered 500 for a handler with
no `return`.

JsonTransformer now returns status 204 and an empty body (no headers)
for undefined. outcomeToResponse already sends a null body for 204 and
the Node server ends with the empty string, so all four runtimes give
the same answer. null is a JSON value and still renders as 200 `null`.
Routes with their own @Transformer are unchanged.

BREAKING CHANGE: a handler with no return value now answers 204 instead
of an empty 200 on Node (and instead of 500 elsewhere). Return a value
to keep a 200.

test/undefined-return.test.ts covers app.fetch and the Node server
(both fail without the fix) and pins null to 200.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx force-pushed fix/undefined-return-204 from ee5f84aa61 to 40702aef2a 2026-10-25 03:49:51 +00:00 Compare
chrnx merged commit dd3a74afcd into develop 2026-10-25 03:51:59 +00:00
Sign in to join this conversation.