Skip to content

fix: add error handling to authentication controllers#56

Open
om-dev007 wants to merge 2 commits into
rishabhx29:mainfrom
om-dev007:fix/issue-53-auth-error-handling
Open

fix: add error handling to authentication controllers#56
om-dev007 wants to merge 2 commits into
rishabhx29:mainfrom
om-dev007:fix/issue-53-auth-error-handling

Conversation

@om-dev007

@om-dev007 om-dev007 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds proper error handling to authentication controllers by wrapping asynchronous operations in try-catch blocks.

Changes Made
Added try-catch blocks to registerUser
Added try-catch blocks to loginUser
Improved error handling for authentication-related operations
Added server error responses for unexpected failures
Added error logging for easier debugging
Why

Authentication controllers perform multiple asynchronous operations such as database queries and password hashing. Without proper error handling, unexpected failures can lead to unhandled exceptions and inconsistent API responses.

Issue

Closes #53

Summary by CodeRabbit

  • Bug Fixes
    • User registration now returns descriptive error messages when unexpected errors occur
    • Google authentication error responses are now more consistent and informative

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@om-dev007 is attempting to deploy a commit to the rishabhjtripathi2903-3434's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

Next review available in: 50 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 Plus

Run ID: f12c7e48-2dce-4db0-a814-3200c1b18ff2

📥 Commits

Reviewing files that changed from the base of the PR and between b83d353 and c28c339.

📒 Files selected for processing (1)
  • backend/src/controllers/authController.ts
📝 Walkthrough

Walkthrough

registerUser in authController.ts is wrapped in a try/catch block so unhandled runtime errors return a 500 response with { success: false, message } instead of crashing the request. googleAuth's catch block is changed from returning 400 with { message: 'Google Auth Failed' } to logging Google Auth Error: and returning 500 with { success: false, message: 'Google authentication failed' }.

Changes

Auth Controller Error Handling

Layer / File(s) Summary
registerUser try/catch and googleAuth 500 response
backend/src/controllers/authController.ts
registerUser wraps the full registration flow in a try/catch; unhandled exceptions are logged and return 500 with { success: false, message }. googleAuth's catch block switches from 400 { message: 'Google Auth Failed' } to a logged 500 { success: false, message: 'Google authentication failed' }. getMe is unchanged beyond minor formatting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 Hop hop, no more crashes in the night,
When Prisma stumbles, we catch it right!
A try wraps the login, a catch holds the fall,
Five-hundred replies stand guard for us all.
The rabbit sleeps soundly — errors are tamed. 🌙

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding error handling to authentication controllers, which is the core objective of this PR.
Linked Issues check ✅ Passed The PR implements try-catch blocks in registerUser and googleAuth, and adds standardized error responses and error logging as required by issue #53, though loginUser changes are not detailed.
Out of Scope Changes check ✅ Passed All changes are focused on error handling in authentication controllers, directly aligned with issue #53; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/controllers/authController.ts`:
- Around line 64-67: The catch blocks in authController.ts are exposing raw
error messages to clients, which leaks internal implementation details and
violates security practices. In both the catch block around lines 64-67 and the
one around lines 103-105, replace the dynamic error.message with a fixed generic
message like "Internal server error" in the res.status(500).json() response.
Keep the detailed error information (error.message and full error object) only
in server-side logging using a logger or console.error so debugging information
is available internally but not exposed to clients.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 049a1f9a-7534-4ace-90f3-9eabb34ea26f

📥 Commits

Reviewing files that changed from the base of the PR and between e38b451 and b83d353.

📒 Files selected for processing (1)
  • backend/src/controllers/authController.ts

Comment thread backend/src/controllers/authController.ts
@rishabhx29 rishabhx29 added enhancement New feature or request SSoC26 Medium labels Jun 24, 2026
@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
algo-forge-2-0 Ready Ready Preview, Comment Jul 4, 2026 9:10am

@om-dev007

Copy link
Copy Markdown
Contributor Author

@Rishabhworkspace please review the latest commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Medium SSoC26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Proper Error Handling in Authentication Controllers

2 participants