felixmosh / bull-board

🎯 Queue background jobs inspector
MIT License
2.14k stars 343 forks source link

BUG: Error thrown when calling HonoAdapter API with status code 204 #735

Closed hongfanmeng closed 1 month ago

hongfanmeng commented 1 month ago

When using HonoAdapter, the following error thrown when calling the API with status code 204

TypeError: Response constructor: Invalid response status code 204
    at webidl.errors.exception (node:internal/deps/undici/undici:1801:14)
    at initializeResponse (node:internal/deps/undici/undici:5919:31)
    at new Response (node:internal/deps/undici/undici:5713:9)
    at [getResponseCache] (/home/steven/repo/working/lh/bull/node_modules/@hono/node-server/dist/index.js:231:36)
    at _Response.get (/home/steven/repo/working/lh/bull/node_modules/@hono/node-server/dist/index.js:271:36)
    at Context.newResponse (/home/steven/repo/working/lh/bull/node_modules/hono/dist/cjs/context.js:134:33)
    at Context.text (/home/steven/repo/working/lh/bull/node_modules/hono/dist/cjs/context.js:166:45)
    at errorHandler (/home/steven/repo/working/lh/bull/node_modules/hono/dist/cjs/hono-base.js:64:12)
    at dispatch (/home/steven/repo/working/lh/bull/node_modules/hono/dist/cjs/compose.js:57:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This is because Hono only accepts an empty body when status code is 204, and the existing API returns an empty json {}.

To solve this problem, adding the following code to HonoAdapter in packages/hono/src/HonoAdapter.ts

+   if (response.status == 204) return c.body(null, 204);
    return c.json(response.body, response.status || 200);
felixmosh commented 1 month ago

Will you be able to make a pr for this?