Skip to content

[Request]: Structured JSON error body for request.body.schema 422 responses #320

Closed

Description

@jimhoyd

Follow-up to #254 (shipped in #306).

The maintainer decision asked for a structured 400/422 on body-schema failure. #306 answers 422 with a plain-text message. Add a JSON error body (for example the failing JSON pointer and keyword, never the offending value) when the client accepts JSON, keeping the plain-text form otherwise, and document it in docs/SPECIFICATION.md.

Also unverified in #306: behavior on a real Cloudflare Worker (workerd/wrangler); parity was tested by running the built Worker code in Node.

Activity

  1. added
    enhancement
    ai-first
    in-progress
    on Sep 20, 2026
  2. jimhoyd commented on Sep 20, 2026

    @jimhoyd
    CollaboratorAuthor

    Progress: an agent has started on this; a PR will be linked here when it opens.

  3. jimhoyd commented on Sep 20, 2026

    @jimhoyd
    CollaboratorAuthor

    Progress: PR #333 opened: 422 body-schema failures return a structured JSON body ({error, message, issues[]} with a schema-derived pointer, keyword and expected constraint, never a value) when the client explicitly accepts application/json; plain text otherwise.

  4. jimhoyd commented on Sep 20, 2026

    @jimhoyd
    CollaboratorAuthor

    Shipped in #333: body-schema 422 responses return {error, message, issues[]} JSON when the client explicitly accepts application/json (pointer built only from schema-declared names, keyword, expected constraint; never a value; at most 8 issues and 4096 bytes), plain text otherwise. Worker parity is tested by running the built handler in Node, not on workerd or wrangler, so real-Worker behavior is still unverified; keeping this open for that.

  5. added
    important
    in-progress
    and removed
    in-progress
    on Sep 20, 2026
  6. jimhoyd commented on Sep 21, 2026

    @jimhoyd
    CollaboratorAuthor

    Progress: an agent has started on this; a PR will be linked here when it opens.

  7. jimhoyd commented on Sep 21, 2026

    @jimhoyd
    CollaboratorAuthor

    Progress: PR #381 opened: the Cloudflare build of examples/body-validation was run on real workerd (Wrangler 4.136.0, local, nothing deployed) and returned byte-identical responses to the Node server for 16 requests, including the structured 422 body; recorded in docs/CLOUDFLARE.md with npm run test:workerd to repeat it.

  8. removed
    in-progress
    on Sep 21, 2026
  9. jimhoyd commented on Sep 21, 2026

    @jimhoyd
    CollaboratorAuthor

    Verified and documented in #381: the Cloudflare build of examples/body-validation ran on real workerd (Wrangler 4.136.0 with workerd 2026-09-21, local, nothing deployed) and returned byte-identical status, headers and bodies to the Node server for 16 requests (structured 422 JSON, plain-text fallbacks, 400/413/415, format: uuid, and the 128-character worst-case pattern at about 2 ms), with no eval or new Function in the generated Worker. Excluded from the comparison: the per-request X-Request-Id and workerd's gzip of the response when the client sends Accept-Encoding (decoded body identical). npm run test:workerd repeats it (needs the network, installs Wrangler into a temp directory, skips when workerd cannot start). Not covered: Cloudflare's network, CPU limits, real request-size limits and edge compression, so behavior on a real deployment is still unverified; the docs say so.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-firstenhancementimportant

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions