feat: Implement authentication error handling #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces a robust, reusable authentication error handling utility and applies it throughout the frontend codebase. The main goal is to standardize how authentication/session expiration errors are detected and reported, ensuring users receive clear, actionable error messages and that expired sessions are handled gracefully.
Key changes:
Authentication Error Handling Utility
Added a new
authErrorHandlerutility (frontend/utils/authErrorHandler.ts) that provides three main functions:isAuthenticationExpiredError,getAuthErrorMessage, andshouldRedirectToLogin. These help detect expired sessions, generate user-friendly error messages, and determine when to redirect users to the login page.Comprehensive unit tests were added for this utility in
frontend/__tests__/utils/authErrorHandler.test.ts, ensuring correct detection and messaging for various authentication error scenarios.Integration Across Services
dbService.tsanduserDataService.tsto use the new error handling utility. Token acquisition and API calls now use helper functions that catch authentication errors, throw user-friendly messages, and propagate other errors as-is. This improves reliability and consistency in error handling for all database and user data operations. [1] [2] [3] [4] [5] [6] [7] [8] [9]UI Error Handling Improvements
QueryGeneratorPage.tsxto use the new utility for displaying authentication errors to users. Now, session expiration and permission errors are clearly distinguished and shown with appropriate guidance, and authentication errors during background operations are logged for debugging. [1] [2] [3] [4]