Skip to content

feat: graceful API contract for malformed requests (P2) - #11

Merged
PG1204 merged 1 commit into
mainfrom
p2-api-contract
Jun 15, 2026
Merged

feat: graceful API contract for malformed requests (P2)#11
PG1204 merged 1 commit into
mainfrom
p2-api-contract

Conversation

@PG1204

@PG1204 PG1204 commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the API-contract gap: malformed input now follows the same graceful-degradation contract as every other failure path.

  • @RestControllerAdvice maps an unreadable/empty request body to HTTP 200 with a PrAnalysisResponse envelope (overallRisk=PARSING_ERROR) instead of Spring's default 400.
  • Extracted PayloadTooLargeException to a public top-level class; an over-limit chunked body (no Content-Length) now returns 413, consistent with the P0 size-limit filter (previously surfaced as 400).
  • Security rejections (401/413/429 from filters) are unchanged — only the analysis path is always-200.

Testing

  • GlobalExceptionHandlerTest — unit, both branches (200 envelope + 413).
  • AnalysisControllerWebTest@WebMvcTest: malformed/empty → 200 envelope, valid → delegates to service.
  • Full suite: 52 passing (live GoldenDiffTest excluded — needs real key + network).

Notes

  • Malformed requests reuse the existing PARSING_ERROR value (no enum change).
  • 415/405 intentionally left as standard status codes.

- Add GlobalExceptionHandler (@RestControllerAdvice): a malformed or empty
  request body now returns HTTP 200 with a PrAnalysisResponse envelope
  (overallRisk=PARSING_ERROR) instead of Spring's default 400, honoring the
  documented always-200 graceful-degradation contract.
- Extract PayloadTooLargeException to a public top-level class; the advice maps
  an over-limit chunked body to 413, consistent with the P0 size filter (this
  case previously leaked through as a 400).
- Tests: GlobalExceptionHandlerTest (unit, both branches) and a @WebMvcTest
  covering malformed/empty -> 200 envelope and valid -> service delegation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

💥 Blast Radius Analysis

Overall Risk: ❓ UNKNOWN

🔍 Impact Areas

  • Analysis service was unreachable — this check is advisory and does not block the PR.

🧪 Suggested Tests

  • None suggested

Analyzed by Blast Radius (Spring Boot + Groq LLM) • 2026-06-15

@PG1204
PG1204 merged commit a242ab4 into main Jun 15, 2026
2 checks passed
PG1204 added a commit that referenced this pull request Jul 7, 2026
Merge pull request #11 from PG1204/p2-api-contract
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant