feat: enhance error handling in git-push and repo services#1406
feat: enhance error handling in git-push and repo services#1406jescalada merged 13 commits intofinos:mainfrom
Conversation
… for error scenarios
- Add new test file for errors.ts utility functions (18 tests) - Expand git-push.test.ts to cover getPush and getPushes functions (13 tests total) - Expand repo.test.ts to cover getRepos, addRepo, deleteUser, and deleteRepo (21 tests total) - Add new test file for user.ts service functions (13 tests) - All tests verify both success and error handling scenarios - Total test count increased from 14 to 79 tests for UI services
✅ Deploy Preview for endearing-brigadeiros-63f9d0 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1406 +/- ##
=======================================
Coverage 81.78% 81.78%
=======================================
Files 67 67
Lines 4766 4766
Branches 827 827
=======================================
Hits 3898 3898
Misses 852 852
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jescalada
left a comment
There was a problem hiding this comment.
Looks good so far, thanks for all the extra UI tests!
What I had in mind when I first made the error handling refactor ticket was some sort of wrapper component (context?) that would catch any errors happening in API calls and forward the error to a toast. I'm aware this would require a lot of extra refactoring, so I might have to clarify the details and we can deal with it in a separate PR.
Note that I haven't tested behavior yet - will complete the review later this week 👍🏼
kriswest
left a comment
There was a problem hiding this comment.
Very happy to see this being done (particularly redirects to login on 401s and use of the API's error messages) and would love it to go into 2.0 (as the current situation is awful). I only have a couple of minor comments to add to Juan's.
I have explored universal API error messaging. It is doable with shared axios instance with a response interceptor + Addition to this PR: |
jescalada
left a comment
There was a problem hiding this comment.
I noticed a few errors that are either caught elsewhere or don't make it into the ErrorBoundary:
Non-existent user
Non-existent push
This might happen if accessing a link to a push that later got removed from the database somehow:
For /dashboard/repo/<repo-id> this is working correctly:
Another thing I noticed is that we still get the errors in the console. Not sure if we should keep these for debugging (as they sometimes contain additional context vs. the stack trace) or not.
|
LGTM after fixing those! 👍🏼 |
|
@jescalada Addressed both issues:
|
…inked # Conflicts: # src/ui/services/git-push.ts # src/ui/views/PushDetails/PushDetails.tsx
Summary
This PR fixes both:
Improve error handling and test coverage for UI services
This PR refactors error handling across the UI service layer and adds comprehensive test coverage. Error handling is now consistent, type-safe, and properly tested.
What's changed
Error handling improvements:
src/ui/services/errors.tswith reusable error utilities (getServiceError,errorResult,successResult)git-push.tsandrepo.tsservices to use the new error handling utilitiesPushDetails.tsx,RepoDetails.tsx, etc.) to properly handle and display error statesServiceResult<T>objects with success/failure statesTest coverage (14 → 79 tests):
test/ui/errors.test.ts- comprehensive tests for error utility functions (18 tests)test/ui/user.test.ts- tests for user service functions (13 tests)test/ui/git-push.test.ts- expanded coverage for all git-push functions (13 tests)test/ui/repo.test.ts- expanded coverage for all repo functions (21 tests)Tests cover success paths, HTTP errors (401/403/404/409/500), network failures, and edge cases.
Benefits
Addition to this PR - Error Boundary
New file
src/ui/components/ErrorBoundary/ErrorBoundary.tsxErrorBoundary class component with getDerivedStateFromError (render capture) + componentDidCatch (logging)
Wraps all route content in and catches any render error from any view without taking down the sidebar/navbar
It has 2 modes -
devandproduction. Indevmode it has option to display stacktrace of the error, in production mode only offers option to reload:DEV:

PROD:
