Repository navigation
🐛 fix(api): return 400 with clear messages for invalid request bodies - #100
Merged
Merged
Conversation
Routes parsed bodies with a bare `schema.parse`, so any invalid input surfaced as an unhandled 500. `parseRequestBody` turns validation failures into a 400 that lists each problem by field. ID fields now name the kind of ID a caller passed by mistake, e.g. a source ID sent as `nodeId`, so an assistant can correct the call. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FNR7YyDx7o2aCjAY4BPbEu
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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 and why
Petals'
getNodetool sent a source ID (src_…) asnodeId.POST /node/sourcesthrew a rawZodError, and Nitro returned it as an unhandled 500 with no useful body. This happened on every route, because each one parsed its body with a bareschema.parse(await readBody(event)).parseRequestBody(schema, body)(src/lib/request-body.ts): turns a validation failure into400 Invalid request body. Themessagelists each problem with its field path (z.prettifyError), anddata.issuesholds the Zod issues. All 81 body-parsing routes now use it. I made this change with an ast-grep codemod.sources/identity/lifecycleusedreadValidatedBodybefore; it now uses the same helper.typeIdSchemaerrors name the wrong ID kind. For a source ID passed as a node ID, the error is:Expected a node ID starting with "node_", but received a source ID. Use a source operation for this ID instead.The prefix check stops validation, so the caller gets one clear issue and not also a length error. The MCP tools use the same schemas, so they get this message too..parsecalls are unchanged. A response that does not match its schema is a server bug and should stay a 500.How to test
pnpm exec vitest run src/node-sources-route.test.ts src/types/typeid.test.tsOr send
POST /node/sourceswith{"userId":"…","nodeId":"src_01m34wpw4fesks6rketcme5875"}. The response is a 400 that includes the message above.Status
pnpm run build:check(tsc + structured-output schema check): passpnpm run lint,pnpm run format,pnpm run build-sdk,pnpm run build: passmain: the tests have noDATABASE_URLorMEMORY_OPENAI_*environment variables (partition-reclassification,query/change-feed,email-request-matching.integration)./node/sources. I updated thechange-feedandidentity lifecycleroute tests to expect the new error shape.docs/sdk-consumer-migration.mdhas a new entry for the changed error behavior.🤖 Generated with Claude Code
https://claude.ai/code/session_01FNR7YyDx7o2aCjAY4BPbEu