Skip to content

fix signuploginerrorhandling #34 issue part-1#44

Open
arpitasi1gh wants to merge 1 commit into
niharika-mente:mainfrom
arpitasi1gh:fixbug/signuploginerrorhandling
Open

fix signuploginerrorhandling #34 issue part-1#44
arpitasi1gh wants to merge 1 commit into
niharika-mente:mainfrom
arpitasi1gh:fixbug/signuploginerrorhandling

Conversation

@arpitasi1gh

@arpitasi1gh arpitasi1gh commented Jun 11, 2026

Copy link
Copy Markdown

Related Issue

Addresses part of #34

Problem

Users were not seeing actual error messages from the backend during signup/login failures. The AuthContext was catching all errors internally and only returning true/false, causing pages to never receive the exceptions they were trying to catch.

Solution

  • Refactored AuthContext.register() and AuthContext.login() to throw errors instead of catching them internally
  • Updated Signup.jsx and Login.jsx error handling to properly catch and display backend error messages
  • Added support for both message and error fields from API responses
  • Improved HTTP status code handling (400, 401, 404, 409, 500)

Result

Users now see helpful, specific error messages:

  • "User already exists" for duplicate registrations
  • "Invalid email or password" for failed logins
  • Validation errors from the backend
  • Server errors when applicable

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced error messaging on login page with status-specific messages for invalid credentials, account not found, and server errors.
    • Improved error messaging on signup page with clearer messages for invalid input, existing accounts, and server issues.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

AuthContext removes try/catch blocks from register and login functions, allowing API errors to propagate uncaught. Login and Signup pages implement robust error handling by extracting server messages and setting user-facing messages based on HTTP status codes.

Changes

Auth Error Handling Refactor

Layer / File(s) Summary
AuthContext error propagation
frontend/src/context/AuthContext.jsx
register and login functions remove try/catch blocks around API calls, eliminating internal error logging and returning false only when response.data.success is falsy; errors now propagate uncaught to calling components.
Login and Signup error handlers
frontend/src/pages/Login.jsx, frontend/src/pages/Signup.jsx
Both pages implement robust error handling in catch blocks by extracting server messages from err.response.data.message or .error, then setting user-facing error messages based on HTTP status codes: Login handles 401 (invalid credentials), 404 (account not found), and 500 (server error); Signup handles 400 (invalid input), 409 (user already exists), and 500 (server error).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Errors now hop where they're meant to,
From context to pages, a cleaner debut,
Server messages speak, status codes guide,
User sees why they can't sign inside!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title mentions fixing signup/login error handling (#34 issue part-1), which directly corresponds to the main changes refactoring error handling in AuthContext, Signup, and Login pages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
frontend/src/pages/Login.jsx (1)

40-53: ⚡ Quick win

Extract shared auth error parsing/mapping to a helper.

err.response parsing and status-to-message branching now exists here and in frontend/src/pages/Signup.jsx (Line 53-64). Centralizing this logic will prevent message/status drift as backend error contracts evolve.

♻️ Suggested direction
+// frontend/src/lib/authErrorMessage.js
+export function getAuthErrorMessage(err, mode = "login") {
+  const statusCode = err.response?.status;
+  const errorMsg = err.response?.data?.message || err.response?.data?.error;
+
+  if (mode === "login") {
+    if (statusCode === 401) return errorMsg || "Invalid email or password. Please try again.";
+    if (statusCode === 404) return "Account not found. Please sign up first.";
+    if (statusCode === 500) return "Server error. Please try again later.";
+    return errorMsg || "Login failed. Please check your credentials.";
+  }
+
+  if (mode === "signup") {
+    if (statusCode === 400) return errorMsg || "Invalid input. Please check your details.";
+    if (statusCode === 409) return "User already exists. Please login instead.";
+    if (statusCode === 500) return "Server error. Please try again later.";
+    return errorMsg || "Registration failed. Please try again.";
+  }
+}
🤖 Prompt for 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.

In `@frontend/src/pages/Login.jsx` around lines 40 - 53, Extract the status+body
parsing into a shared helper (e.g., parseAuthErrorResponse) that accepts the
caught error object and returns a finalized user-facing message; implement it to
read err.response?.status and err.response?.data?.message ||
err.response?.data?.error and map 401/404/500 to the same default strings shown
here and fall back to the raw errorMsg or a generic login failure text. Export
this helper from a new util (e.g., frontend/src/utils/authErrors.js) and replace
the inline logic in Login.jsx (the block using statusCode/errorMsg and setError)
and the same block in Signup.jsx to simply call
setError(parseAuthErrorResponse(err)). Ensure imports are added and
tests/behavior remain identical to the current mapping.
🤖 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.

Nitpick comments:
In `@frontend/src/pages/Login.jsx`:
- Around line 40-53: Extract the status+body parsing into a shared helper (e.g.,
parseAuthErrorResponse) that accepts the caught error object and returns a
finalized user-facing message; implement it to read err.response?.status and
err.response?.data?.message || err.response?.data?.error and map 401/404/500 to
the same default strings shown here and fall back to the raw errorMsg or a
generic login failure text. Export this helper from a new util (e.g.,
frontend/src/utils/authErrors.js) and replace the inline logic in Login.jsx (the
block using statusCode/errorMsg and setError) and the same block in Signup.jsx
to simply call setError(parseAuthErrorResponse(err)). Ensure imports are added
and tests/behavior remain identical to the current mapping.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2984ee35-f944-4dc4-bb9f-3413382513c9

📥 Commits

Reviewing files that changed from the base of the PR and between 1bb5406 and 08f59f0.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • frontend/src/context/AuthContext.jsx
  • frontend/src/pages/Login.jsx
  • frontend/src/pages/Signup.jsx

@SparshM8

Copy link
Copy Markdown
Collaborator

Hey @arpitasi1gh, great work on this! Getting these error messages to properly display on the frontend is a massive UX improvement.

The logic looks solid, but before we merge, let's take a look at the nitpick comment left by the coderabbitai bot. Since the error-parsing logic is nearly identical in both Login.jsx and Signup.jsx, it's a great best practice to extract that into a shared helper function (like getAuthErrorMessage). This keeps our codebase DRY (Don't Repeat Yourself) and makes future changes much easier!

Could you implement that quick refactor? Once that's done, I'll get this merged right away.

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.

2 participants