fix(web): classify invalid JSON request bodies - #404
Merged
Conversation
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.
Problem
Refs #403.
Malformed JSON, non-object JSON, and request bodies larger than the Web Host's 16 KiB command limit are recognized at the input boundary, but their ordinary
Errorvalues reach the generic dispatcher fallback and are all reported as HTTP 500. This misclassifies client input as a server failure.Value
Clients can distinguish requests they must correct from retryable server failures. Stable machine-readable codes keep retry behavior, monitoring, and failure evidence accurate as more Web endpoints reuse the same JSON parser.
Approach
WebRequestErrorat the Web Host HTTP boundary, carrying a bounded status code, stable error code, and optional byte limit.400 INVALID_REQUEST_BODYfor malformed or non-object JSON.413 REQUEST_BODY_TOO_LARGEwithmaxBytesfor bodies over 16 KiB.WebHostfor all three client-input cases and an unexpected adapter failure.Validation
bun run check— passed (config contract, discipline ledger, Web syntax, formatting, lint, and TypeScript).node --test --experimental-strip-types tests/web/web-host.test.ts— passed, 21/21.bun run test— Web Host tests passed; repository total was 1240 passed, 2 failed, 5 skipped. Both failures were outside this change: an Antigravity stalled-body timing test passed when rerun alone, while the pre-existing Windows reused-PID setup-lock test still timed out when rerun alone.Impact