Skip to content

fix: add centralized backend error handling#92

Open
saurabhhhcodes wants to merge 2 commits into
ThePlator:mainfrom
saurabhhhcodes:fix/global-error-handler-88
Open

fix: add centralized backend error handling#92
saurabhhhcodes wants to merge 2 commits into
ThePlator:mainfrom
saurabhhhcodes:fix/global-error-handler-88

Conversation

@saurabhhhcodes

Copy link
Copy Markdown

Summary

  • adds a centralized Express error handler and 404 handler for backend API responses
  • adds an async route wrapper so controller failures flow through one middleware path
  • removes repeated generic 500 catch blocks from auth/message controllers while preserving explicit 400/401/404 responses
  • changes the root health text route to GET / so unknown routes can return structured 404 JSON

Validation

  • node --check backend/middleware/errorHandler.js
  • node --check backend/server.js
  • node --check backend/routes/user.routes.js
  • node --check backend/routes/message.routes.js
  • node --check backend/controllers/user.controller.js
  • node --check backend/controllers/message.controller.js
  • git diff --check

Fixes #88

Suggested labels: gssoc:approved, level:intermediate, quality:clean, type:bug, type:backend, type:refactor.

@vercel

vercel Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the Sameer's projects Team on Vercel.

A member of the Team first needs to authorize it.

@saurabhhhcodes saurabhhhcodes force-pushed the fix/global-error-handler-88 branch from 33ceabf to b158c2a Compare May 19, 2026 19:40
@saurabhhhcodes

Copy link
Copy Markdown
Author

Rebased this PR onto the latest main and resolved the conflicts in backend/server.js and backend/routes/user.routes.js.

Resolution notes:

  • kept the latest upstream Helmet/rate-limit/validation changes
  • kept the centralized asyncHandler, notFoundHandler, and globalErrorHandler
  • wrapped validated auth handlers with asyncHandler instead of dropping validation
  • kept the root route as GET / so the not-found handler can catch unknown routes

Validation after rebase:

  • node --check backend/server.js
  • node --check backend/routes/user.routes.js
  • node --check backend/routes/message.routes.js
  • node --check backend/middleware/errorHandler.js
  • git diff --check origin/main...HEAD

All passed locally.

@saurabhhhcodes saurabhhhcodes force-pushed the fix/global-error-handler-88 branch from b158c2a to 76a42e0 Compare May 28, 2026 00:37
@saurabhhhcodes

Copy link
Copy Markdown
Author

Rebased this branch on latest main and resolved the conflicts.

What I preserved while refreshing:

  • latest guest/socket/typing/challenge/Swagger/health behavior from upstream
  • centralized asyncHandler, notFoundHandler, and globalErrorHandler flow from this PR
  • async wrapping on auth/message routes, including newer media/edit/delete message routes

Validation:

  • node --check backend/server.js
  • node --check backend/routes/message.routes.js
  • node --check backend/routes/user.routes.js
  • node --check backend/middleware/errorHandler.js
  • git diff --check

I also ran npm --prefix backend test; the suite currently has one unrelated baseline failure in tests/problem.test.js because the test MongoDB setup lacks the text index required for $text search (text index required for $text query). The conflict-repair touched files passed syntax checks.

@saurabhhhcodes

Copy link
Copy Markdown
Author

Rebased this branch on latest main again and resolved the new conflict in backend/routes/message.routes.js.

Resolution notes:

  • kept the upstream message sync and markConversationSeen route additions
  • kept this PR's centralized error-handler flow by wrapping async message routes with asyncHandler
  • preserved the latest upstream frontend/backend message-delivery changes from main

Validation:

  • node --check backend/server.js
  • node --check backend/routes/message.routes.js
  • node --check backend/routes/user.routes.js
  • node --check backend/middleware/errorHandler.js
  • node --check backend/controllers/message.controller.js
  • git diff --check
  • npm --prefix backend test -> 12 test files passed, 73 tests passed

The only red check currently shown is Vercel team authorization for this repo; local backend validation is green after the conflict repair.

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.

Missing Global Error Handling Middleware

1 participant