Skip to content

fix(rest/nodejs): answer validation failures with the UCP error envelope - #192

Open
vishkaty wants to merge 2 commits into
Universal-Commerce-Protocol:mainfrom
vishkaty:fix/validation-error-envelope
Open

fix(rest/nodejs): answer validation failures with the UCP error envelope#192
vishkaty wants to merge 2 commits into
Universal-Commerce-Protocol:mainfrom
vishkaty:fix/validation-error-envelope

Conversation

@vishkaty

Copy link
Copy Markdown
Contributor

What

A request rejected by payload validation draws a plain text 422 built from the raw zod issues. A validation failure is the only rejection this server still answers as plain text, and the checkout error taxonomy has answered with the UCP envelope since #174. checkout-rest.md gives protocol errors one shape, a JSON body carrying code and content, so a platform can act on the rejection.

POST /checkout-sessions
{"line_items": "not-an-array"}

HTTP 422  content-type: text/plain
✖ Expected array, received string
  → at line_items

Fix

prettyValidation keeps building the same readable diagnostic and now renders it through the existing ucpErrorResponse helper as INVALID_REQUEST with status 422, so the envelope carries the diagnostic as content. Log output is unchanged.

Testing

  • New test/validation_envelope.test.ts: a validation failure must answer application/json in the UCP envelope shape with the offending member named in content, and a valid create still returns 201. The envelope test fails on main and passes with the fix; the suite is 154 passing with it.
  • Sweep: a schema guided sweep of 261 request mutations drew 122 plain text rejections on main and zero after this change, with no other bucket moving.

A request rejected by payload validation drew a plain text 422 built from
the raw zod issues, while every other protocol error on this server speaks
the UCP envelope. checkout-rest.md gives protocol errors one shape, a JSON
body carrying code and content, so the platform can act on the rejection.
prettyValidation now renders the same pretty diagnostic through
ucpErrorResponse as INVALID_REQUEST with status 422, keeping the log output
unchanged. A schema guided sweep of 261 request mutations drew 122 of these
text rejections before the change and zero after.
@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Aug 20, 2026
@damaz91 damaz91 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Aug 20, 2026
@carolinerg1

Copy link
Copy Markdown

Hi @vishkaty, thank you for submitting this fix. This is minor, just formatting feedback, but it looks like it's failing Lint test - could you please take a look at "return ucpErrorResponse" and split the arguments across multiple lines.

@vishkaty

Copy link
Copy Markdown
Contributor Author

Done, split in bdbf45a and the pinned pre-commit now passes on both files. Thank you for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants