fix: return M_BAD_JSON for valid-JSON-wrong-shape request bodies#235
Merged
Conversation
The Json extractor returned M_NOT_JSON for every deserialization failure, including bodies that are valid JSON but don't fit a typed endpoint's shape (a missing key or wrong-typed value) — the spec calls those M_BAD_JSON, and reserves M_NOT_JSON for bodies that aren't valid JSON at all. Classify the serde error: Category::Data → M_BAD_JSON, Syntax/Eof → M_NOT_JSON.
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.
The
Json<T>extractor returnedM_NOT_JSONfor every deserialization failure, including bodies that are valid JSON but don't fit a typed endpoint's shape (a missing required key, or a wrong-typed value). The spec reservesM_NOT_JSONfor bodies that aren't valid JSON at all and usesM_BAD_JSONfor "valid JSON, but malformed in some way, e.g. missing required keys or invalid values."Classify the
serde_jsonerror:Category::Data→M_BAD_JSON;Syntax/Eof/Io→M_NOT_JSON.Json<Value>handlers are unaffected (any valid JSON deserializes toValue, soDatanever fires — they keep returningM_NOT_JSONonly for genuinely unparseable bodies, and do their own shape validation withM_BAD_JSON).Existing
M_NOT_JSONcases are preserved: invalid UTF-8 and plain non-JSON bodies classify asSyntax, notData.Test covers the four cases (syntax, eof, wrong-type, missing-field).