fix: survey submission returns 204 instead of an empty-bodied 201 - #86
Merged
Conversation
Submitting a survey response worked server-side but the frontend toasted "Couldn't Submit" (SyntaxError: Unexpected end of JSON input). The endpoint returned status 201 with no body via a bare Response(status_code=...), but apiFetch's generic transport only skips res.json() for 204 — every other 201 handler in the backend returns a real Pydantic-serialized JSON body, so this was the only handler that broke that contract. Since the endpoint intentionally has no body to return (frontend expects void), switch it to 204 No Content, matching the codebase's existing convention for action endpoints (see challenge_ratings.rate_challenge). No frontend change needed — apiFetch already special-cases 204. Fixes #81 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DiuFxvVhJ5rg5558EdsJRr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Submitting a survey response as a participant worked (the response was
saved and
survey.submittedwas emitted correctly), but the UI toasted"Couldn't Submit" /
Failed to execute 'json' on 'Response': Unexpected end of JSON input.Root cause:
submit_response(backend/routers/feedback.py) returnedResponse(status_code=status.HTTP_201_CREATED)— a 201 with an emptybody. The frontend's shared
apiFetchtransport(
frontend/src/lib/api.ts) only skipsres.json()for a204status;every other status, including this bare 201, falls through to
res.json(), which throws aSyntaxErroron the empty body. This wasthe only
201handler in the backend that didn't return a realPydantic-serialized JSON body — every other one does.
Fix: since this endpoint genuinely has nothing to return (the frontend
already expects
void), change it to204 No Contentinstead ofinventing a JSON body — this matches the codebase's existing convention
for action-only endpoints (e.g.
challenge_ratings.rate_challenge,survey.delete, etc., all-> Nonewithstatus_code=HTTP_204_NO_CONTENT).No frontend change is required —
apiFetchalready special-cases204.Updated the three
test_feedback.pyassertions that checkedstatus_code == 201on this endpoint to204.Fixes #81
Other notes
204-only special case were both introducedin the initial squashed import commit (
31e1e99) — not a laterregression — and were confirmed via repro analysis in a prior comment
on the issue.
201handlers were found with the same empty-bodypattern (checked via grep), so this looks like an isolated instance
rather than a class of bug.
apiFetchempty-body handling was intentionally left alone rather thanbroadened, since the backend-side fix is more correct and lower-risk
(it doesn't touch the shared transport used by every API call).
Checklist
cd backend && .venv/bin/pytest(full suite: 414 passed)cd frontend && npm run test && npx tsc --noEmit && npx eslint .(no frontend files changed by this PR)204status)competition_idscoping,require_permission, one hook per domain, design tokens)YYYY-MM-DD_<revid>_<desc>.py(no schema change)Generated by Claude Code