Skip to content

fix(listener): return after handling GET /api/preferences/:userId#162

Open
giftexceed wants to merge 1 commit into
Core-Foundry:mainfrom
giftexceed:fix/listener-preferences-endpoint
Open

fix(listener): return after handling GET /api/preferences/:userId#162
giftexceed wants to merge 1 commit into
Core-Foundry:mainfrom
giftexceed:fix/listener-preferences-endpoint

Conversation

@giftexceed

Copy link
Copy Markdown

Summary

Fixes a crash in the listener's GET /api/preferences/:userId endpoint.

The handler wrote its response with res.end(...) but did not return, so execution fell through to the catch-all 404 handler at the bottom of the request listener, which called res.writeHead(404, ...) on an already-sent response and threw:

Cannot write headers after they are sent to the client
  at Server.<anonymous> (src/api/events-server.ts:519:9)

The fix sets the explicit 200 status with a JSON content-type header and returns after responding, matching every other route handler in the file.

Why this matters for CI

This is one of two pre-existing test failures in the listener on main (unrelated to any contract/dashboard work) that make the CI / Listener job red. This PR fixes the events-server.test.ts failure.

Verification

npx jest src/api/events-server.test.ts   →  15 passed (was 1 failing)
npx tsc --noEmit                          →  clean

The GET preferences handler wrote its response but did not return, so
execution fell through to the catch-all 404 handler, which called
res.writeHead() again and threw "Cannot write headers after they are
sent to the client". Add the explicit 200 + JSON content-type header and
return after responding, matching the other route handlers.

Fixes the failing "GET /api/preferences/:userId returns preferences for
the given user" test in events-server.test.ts.
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