Fix registration update API crash: headers already sent#1977
Merged
Conversation
Replace broken writeHead(404).json() with status(404).json(), clear stale cookie on 404, and redirect user to /join to re-register. Fixes #1965 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The cookie gets cleared on the final successful form step. If additional PATCH requests arrive after that, email is undefined and the Airtable lookup fails — this was the actual trigger for the writeHead crash. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Deployment failed with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
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.
Summary
Fixes #1965
The PATCH /api/registration/update endpoint was crashing with "Cannot set headers after they are sent to the client" (Sentry FRONT-END-86, 9 occurrences).
Root cause
When a user completes the final registration step, the API clears the opCodeApplicantEmail cookie. But the multi-step form fires additional PATCH requests after that (e.g. rapid clicking). These arrive with no cookie, the Airtable lookup returns nothing, and the code hits a broken res.writeHead(404).json() path -- writeHead() flushes headers immediately, so the subsequent .json() (which sets Content-Type) throws. The catch block's res.status(500).json() fails for the same reason, producing the unhandled error.
Confirmed by tracing the actual Sentry events: the user had 4 successful 200 PATCHes (filling all fields, which cleared the cookie), followed by 7 consecutive 500s.
Changes
Test plan
🤖 Generated with Claude Code