Skip to content

feat(api): BA-116 reject malformed JSON with safe client 400 error response - #1042

Open
ranjeetprabhatedu-dotcom wants to merge 1 commit into
BlockDash-Studios:mainfrom
ranjeetprabhatedu-dotcom:feat/reject-malformed-json-1029
Open

ranjeetprabhatedu-dotcom wants to merge 1 commit into
BlockDash-Studios:mainfrom
ranjeetprabhatedu-dotcom:feat/reject-malformed-json-1029

Conversation

@ranjeetprabhatedu-dotcom

Copy link
Copy Markdown

Summary

This PR implements BA-116 to reject malformed JSON request bodies with a safe, standardized HTTP 400 client error rather than allowing an unhandled 500 server error.

  • Implements malformedJsonHandler middleware in app.controller.ts and registers it in main.ts to intercept SyntaxError with status 400 from body parsing.
  • Returns a clean JSON error response ({ statusCode: 400, message: 'Malformed JSON payload in request body', error: 'Bad Request' }).
  • Passes non-syntax errors cleanly to next(err) to preserve downstream error handling.
  • Adds comprehensive unit tests in app.controller.spec.ts covering both malformed JSON interception and regular error passthrough.
  • Scoped strictly to the 3 allowlisted files:
    • BackendAcademy/src/main.ts
    • BackendAcademy/src/app.controller.ts
    • BackendAcademy/src/app.controller.spec.ts

Closes #1029

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.

BA-116 — Reject malformed JSON with a client error

1 participant