Skip to content

Conversation

@ChingEnLin
Copy link
Owner

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 authErrorHandler utility (frontend/utils/authErrorHandler.ts) that provides three main functions: isAuthenticationExpiredError, getAuthErrorMessage, and shouldRedirectToLogin. 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

  • Updated dbService.ts and userDataService.ts to 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

  • Updated QueryGeneratorPage.tsx to 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]

Copilot AI review requested due to automatic review settings September 2, 2025 13:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a centralized authentication error handling utility to standardize how authentication/session expiration errors are detected and reported across the frontend codebase, improving user experience with clear error messages and graceful session handling.

  • Implemented a reusable authErrorHandler utility with functions for detecting expired sessions, generating user-friendly messages, and determining login redirects
  • Refactored database and user data services to use standardized error handling for token acquisition
  • Enhanced UI error handling in QueryGeneratorPage to distinguish between authentication and permission errors

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
frontend/utils/authErrorHandler.ts New utility providing authentication error detection and user-friendly messaging
frontend/tests/utils/authErrorHandler.test.ts Comprehensive unit tests for the authentication error handler utility
frontend/services/userDataService.ts Updated token acquisition to use centralized error handling
frontend/services/dbService.ts Refactored to use helper function for authenticated token retrieval with proper error handling
frontend/pages/QueryGeneratorPage.tsx Enhanced error handling to distinguish authentication vs permission errors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ChingEnLin ChingEnLin merged commit c66bf71 into dev Sep 2, 2025
3 checks passed
@ChingEnLin ChingEnLin deleted the feat/add_auth_error_handling branch September 2, 2025 13:52
@github-actions
Copy link

github-actions bot commented Sep 2, 2025

🎉 This PR is included in version 2.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants