Handle invalid JSON in ValidateRepoHandler with 400
Summary
ValidateRepoHandler.post() calls json.loads(self.request.body) without guarding JSONDecodeError, causing a 500 on malformed request payloads.
Why this matters
Invalid client input should produce deterministic 4xx responses, not internal server errors.
Current behavior
Malformed JSON can bubble up as an unhandled exception and return 500.
Expected behavior
Malformed JSON should return 400 Bad Request with a clear error message.
Proposed fix
- Wrap JSON parsing with
try/except (json.JSONDecodeError, ValueError). - Return
HTTPError(400, "Invalid JSON body")(consistent with other handlers). - Add tests for malformed payload handling.
Acceptance criteria
- Malformed JSON returns 400.
- Valid payload behavior is unchanged.
- Tests cover invalid and valid cases.
A fix is now open in PR #62.\n\nThis updates to return a 400 JSON response for malformed request bodies instead of bubbling invalid JSON into a server error path. Focused regression coverage is included in the PR.
Correction: PR #62 specifically updates ValidateRepoHandler to return a 400 JSON response for malformed request bodies instead of bubbling invalid JSON into a server error path. Focused regression coverage is included in the PR.