Repository navigation
refactor(api): route /api/user through a method handler table - #227
Open
dex-the-ai wants to merge 2 commits into
Open
dex-the-ai wants to merge 2 commits into
dex-the-ai wants to merge 2 commits into
Conversation
Split the single if/else handler into one function per HTTP method behind
a methodHandlers table, with parseBody() and sendDbError() as the shared
seams for body parsing and Couchbase error -> HTTP status mapping.
Fixes two edge cases the old shape hid:
- unsupported methods (e.g. PATCH) never received a response and hung;
they now get 405 with an Allow header
- POST/PUT without a body threw on `null.email`; an empty body is now {}
Existing status codes and messages are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ejscribner
approved these changes
Nov 24, 2026
Collaborator
|
@dex-the-ai I think this branch needs to be updated with the latest |
Contributor
Author
|
@ejscribner Done. I merged the latest Checks:
|
This branch was successfully deployed
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
pages/api/user.jswas a singleif/elseoverreq.method. Every branch mixed.then/.catchchains with outertry/catchblocks, and the auth-failure → 401 mapping was copied into three of them. That shape hid two bugs:PATCH /api/userfell through every branch and the request hung until the client timed out.bodystayednull, sobody.emailthrew aTypeError. POST returned an unhandled 500. PUT reported a misleading "Profile Not Found".Change
listProfiles,createProfile,updateProfileanddeleteProfile. AmethodHandlerstable maps methods to these functions and acts as the route's interface.Allow: GET, POST, PUT, DELETEheader. This check runs before connecting to Couchbase.parseBody()parses the body once. A missing body becomes{}, and invalid JSON still returns 400Invalid JSON body.sendDbError()is now the only place that maps SDK errors to HTTP status: 401 forauthentication failure, otherwise 500.All existing status codes and messages are unchanged: 201/200/400/401/500 and their texts. The UI in
pages/index.jschecks these codes, so it is unaffected.Validation
I ran everything locally against Couchbase Server 8.0.3 in Docker, set up like the CI service container: kv+n1ql+index,
user_profilebucket,npm run init-db:default.__test__/api-user-routing.test.jscovers PATCH → 405 +Allowand POST without a body → 400. Onmainboth tests fail: PATCH times out with no response, and the bodyless POST throwsTypeError: Cannot read properties of null (reading 'email'). Both pass on this branch.npm test: 5 suites, 8 tests passed (the 6 existing tests plus the 2 new ones).npm run check(prettier + eslint--max-warnings=0): clean.next dev:AllowInvalid JSON bodyProfile Not Found, cannot update: document not found, the same asmain/→ 200🤖 Generated with Claude Code