Skip to content

Refactor #86: Moved global error handler into a dedicated middleware/…#99

Open
jikrana1 wants to merge 1 commit into
niharika-mente:mainfrom
jikrana1:refactor/issue-86-error-handler
Open

Refactor #86: Moved global error handler into a dedicated middleware/…#99
jikrana1 wants to merge 1 commit into
niharika-mente:mainfrom
jikrana1:refactor/issue-86-error-handler

Conversation

@jikrana1

@jikrana1 jikrana1 commented Jul 2, 2026

Copy link
Copy Markdown

📋 Pull Request — Refactor Global Error Handler into Dedicated Middleware

🔗 Related Issue

Closes #86[Feature]: Refactor Global Error Handler into a Dedicated Middleware Module

✅ Changes Made

  • Extracted the inline global error handling middleware ((err, req, res, next) => {...}) from app.js.
  • Created a new dedicated file: middleware/errorHandler.js (using ES Module syntax).
  • Exported the error handler using export default.
  • Imported and registered the error handler in app.js using app.use(errorHandler) at the very end of the middleware chain (after all routes).
  • Preserved the exact same HTTP 500 response format and error logging behavior.

🧪 Testing Checklist

  • Server starts successfully without errors.
  • Triggering a 500 internal server error (e.g., throwing an error in a controller) returns the exact same JSON error response as before.
  • No breaking changes are introduced.

📌 Benefits Achieved

  • Better separation of concerns – Error handling logic is isolated.
  • Cleaner and more maintainable server entry file.
  • Easier to extend with custom error types or logging in the future.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@jikrana1, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cfb09dd6-c320-4c22-8e47-7364ea57b1cd

📥 Commits

Reviewing files that changed from the base of the PR and between 87148ba and c0d99c2.

📒 Files selected for processing (2)
  • backend/src/middleware/errorHandler.js
  • backend/src/server.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

[Feature] : Refactor Global Error Handler into a Dedicated Middleware Module

1 participant