fix(commandboard-api): return 400 for malformed JSON bodies instead of 500#12
Open
quappefeeder wants to merge 1 commit into
Open
fix(commandboard-api): return 400 for malformed JSON bodies instead of 500#12quappefeeder wants to merge 1 commit into
quappefeeder wants to merge 1 commit into
Conversation
…f 500
Malformed JSON on any POST endpoint previously bubbled a SyntaxError to
the top-level handler, which mapped every throw to 500. Client input
errors now respond 400 { "error": "Invalid JSON body" } via a typed
InvalidJsonBodyError thrown from readJson().
Adds contract tests covering all four POST endpoints plus a control
asserting schema-invalid (but well-formed) bodies still return 422.
Fixes profullstack#11
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.
Fixes #11
Summary
Malformed JSON on any POST endpoint previously bubbled the
SyntaxErrorfromJSON.parseto the top-level handler, which maps every throw to 500. Client input errors now respond 400{ "error": "Invalid JSON body" }.Changes
readJson()catches parse failures and throws a typedInvalidJsonBodyErrorInvalidJsonBodyError→ 400; all other errors still → 500/api/tasks,/api/plugins/sh1pt/actions/publish,/api/plugins/c0mpute/jobs/dispatch,/api/plugins/c0mpute/quotes) returns 400, plus a control asserting well-formed but schema-invalid bodies still return 422Testing
Applied via the ugig gig ("will pay $1 USD for bugs reported and fixed with a PR") — ugig user
liudong-design.