Skip to content

Handle invalid JSON in ValidateRepoHandler with 400 #54

@KerwinTsaiii

Description

@KerwinTsaiii

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions