Skip to content

fix: send join 400 through errorResponse so the frontend can read it - #229

Merged
TheCodeHeist-Coder merged 1 commit into
TheCodeHeist-Coder:mainfrom
Anshuu2004:fix/issue-192-join-error-shape
Oct 29, 2026
Merged

TheCodeHeist-Coder merged 1 commit into
TheCodeHeist-Coder:mainfrom
Anshuu2004:fix/issue-192-join-error-shape

Conversation

@Anshuu2004

Copy link
Copy Markdown
Contributor

What does this PR do?

The join endpoint's 400 for a missing code or username was the only error in http-server that did not go through the shared errorResponse helper. It sent { message: "..." } instead of { success: false, error: "..." }. JoinQuiz.tsx reads response.data.error, so for that response it always fell back to the generic "Failed to join quiz" and the real message was dropped.

I changed that one line in sessionController.ts to errorResponse(res, 400, "Code and username are required"), and added a small test file for joinQuizController so the shape is pinned down.

I did not touch the frontend. JoinQuiz.tsx already reads .error, so it works with the new shape as is.

Related issue

Closes #192

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactoring
  • Performance
  • Tests
  • Build / CI / deployment

Which services does this touch?

  • apps/frontend
  • apps/http-server
  • apps/ws-server
  • apps/genAI
  • packages/db (schema or Prisma changes)
  • Docker / CI

How did you test this?

I grepped all of apps/http-server/src for res.status(...).json(...) and res.sendStatus. The only error path that was not using errorResponse was the one on sessionController.ts line 29. Everything else raw is a success response (200/201), so I left those alone.

I added apps/http-server/src/controllers/sessionController.test.ts, written the same way as authController.test.ts (mocked @repo/db, fake req/res). It checks that an empty body, a missing username, a missing code and an empty username all give a 400 with { success: false, error: "Code and username are required" } and never touch the database. There is also one check that the 404 for an unknown quiz has the same shape.

Commands, run in apps/http-server on a fresh worktree of upstream/main:

pnpm test        # before: 7 files, 75 tests passed
pnpm test        # after:  8 files, 80 tests passed
pnpm check-types # no errors (after running db:generate in packages/db)

I also put the old res.status(400).json({ message }) line back temporarily with the new test in place and the 4 new 400 tests failed, so the test does catch the bug. Then I restored the fix.

I did not run the whole app with docker compose, and I did not open the join screen in a browser. For the frontend I only read JoinQuiz.tsx to confirm it reads data.error. This repo's http-server has no lint script, so I did not run pnpm run lint or pnpm run build.

Checklist

  • I ran pnpm run lint
  • I ran pnpm check-types in apps/http-server (not the root turbo run)
  • I ran pnpm run build
  • The app still starts with docker-compose up
  • I updated documentation if this changes behaviour or setup
  • I did not commit any .env file, API key or other secret

@TheCodeHeist-Coder
TheCodeHeist-Coder merged commit 976d5d8 into TheCodeHeist-Coder:main Oct 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The join endpoint returns an error shape the frontend cannot read

2 participants