Skip to content

feat(api): centralized error handling + 404 JSON#171

Open
imsanupm wants to merge 1 commit intogothinkster:masterfrom
imsanupm:feat/error-handling-middleware
Open

feat(api): centralized error handling + 404 JSON#171
imsanupm wants to merge 1 commit intogothinkster:masterfrom
imsanupm:feat/error-handling-middleware

Conversation

@imsanupm
Copy link
Copy Markdown

feat(api): centralized JSON error handling middleware (no HTML crashes)

What this PR does

Adds production-ready error handling that returns clean JSON responses instead of HTML error pages for all API errors.

Key Improvements

  • All crashes → 500 JSON responses (no HTML crashes)
  • Invalid routes → 404 JSON { "errors": { "body": ["Not Found"] } }
  • MongoDB duplicates → Caught + logged by error handler
  • Server errors → 500 JSON { "errors": { "body": ["Internal server error"] } }

Files changed:

  • src/middleware/error-handler.ts
  • Router: 404 handler + error middleware"
Screenshot From 2026-02-26 23-57-07 Screenshot From 2026-02-26 23-58-25

Production-ready:
- All errors → JSON responses (no HTML)
- 404 Not Found → JSON
- MongoDB duplicates → 422 JSON
- Server crashes → 500 JSON
- Thunder Client tested ✓
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