Extract shared parseBody helper for Zod validation - #598
Merged
selfcontained merged 3 commits intoMay 22, 2026
Conversation
…late Replaces 13 identical safeParse + error-reply blocks across auth.ts, jobs.ts, and templates.ts with a single shared parseBody() function. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Addresses architecture review feedback: - Renamed parseBody→parseInput since it validates both body and query - Constrained generic from ZodType to ZodObject so the undefined-check guard is safe (objects are never falsy) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Completes the round-2 review feedback: the module file now matches the exported parseInput function name. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
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
parseBody()helper intoapps/server/src/shared/lib/parse-body.tsthat wraps the ZodsafeParse+ 400 error reply patternauth.ts(3),jobs.ts(7), andtemplates.ts(3) with one-lineparseBody()callsWhy this is tech debt
The
safeParse→ check!parsed.success→reply.code(400).send({ error: parsed.error.issues[0].message })pattern was copy-pasted verbatim across every route handler that validates request bodies. This made it easy to forget or subtly vary the error format, and added visual noise to every handler.What's next
Next tech debt run will tackle: duplicate constraint-error handler in
personalities.ts(lines 60-67 and 120-127 have identical catch blocks).🤖 Generated with Claude Code