Skip to content

fix: improve error handling — stop silently swallowing errors across backend and frontend#1

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781203756-improve-error-handling
Open

fix: improve error handling — stop silently swallowing errors across backend and frontend#1
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781203756-improve-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Multiple request handlers silently dropped errors by returning without sending an HTTP response (e.g. if (!userId) return;), leaving the client hanging with no feedback. This PR systematically fixes those patterns and several other error-handling gaps.

Backend — silent return → proper HTTP responses:

9 controller handlers (updateUserProfile, deleteUserProfile, getMyFollowers, getMyFollowing, createIssue, updateIssue, deleteIssue, getMyIssues, updateMyIssuesById) had bare if (!userId) return; guards that silently hung the request. Now return 401 Unauthorized.

getMyRepositories and getMyStarredRepos didn't check userId at all before using it as a Prisma where clause — added the same 401 guard.

Backend — middleware:

isAuthenticated and optionalAuth had if(!secret) return; when JWT_SECRET was missing — silently hung every request. Now returns 500 with a logged config error.

Backend — error propagation:

  • blacklistToken swallowed Redis failures → now throws so callers (logout, refresh, delete-user) surface the error. Callers now await it; logoutUser made async.
  • deleteRepository caught Prisma P2025 but throw error'd everything else with no handler → now returns 500.
  • unstarRepository was missing return before sending "You haven't starred this repo" → execution continued and tried to disconnect anyway.
  • copyRepoFilesInS3 had no error handling + no S3_BUCKET env check → added try/catch and throws on failure so the fork flow surfaces errors.

CLI commands: init, addRepo, commitRepo, pushRepo, pullRepo, revertRepo all swallowed errors with console.log and exited 0 → now set process.exitCode = 1.

Frontend hooks:

  • useAuth: Added error state that extracts the API error message (via axios.isAxiosError) instead of console.log("Client side error"). Consumers can now display "wrong password", "User already exists", etc.
  • useUser: Added error state (returned alongside user and loading) so components can render error UI instead of silently showing nothing.

Link to Devin session: https://app.devin.ai/sessions/73fafa714985405a9af113768ba0d919
Requested by: @amnkarn

- Replace silent `if (!userId) return` with proper 401 JSON responses
  in user, issue, and repo controllers
- Fix middleware silent `if(!secret) return` to send 500 responses
  instead of hanging the request
- Make blacklistToken propagate errors (throw) instead of swallowing
- Await blacklistToken calls in auth/user controllers
- Make logoutUser handler async to support await
- Fix deleteRepository re-throwing unhandled error (now returns 500)
- Fix unstarRepository missing return after early response
- Add userId null checks to getMyRepositories/getMyStarredRepos
- Add try/catch and env var validation to copyRepoFilesInS3
- Fix CLI commands to set process.exitCode on failure instead of
  silently swallowing errors
- Frontend useAuth: expose error state with API error message extraction
- Frontend useUser: expose error state for consuming components

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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