aup-learning-cloud icon indicating copy to clipboard operation
aup-learning-cloud copied to clipboard

Handle invalid JSON in ValidateRepoHandler with 400

Open kerwtsai-amd opened this issue 8 months ago • 2 comments

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.

kerwtsai-amd avatar Apr 01 '26 17:04 kerwtsai-amd

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.

MioYuuIH avatar Apr 10 '26 05:04 MioYuuIH

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.

MioYuuIH avatar Apr 10 '26 05:04 MioYuuIH