mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
feat: enhance Google Drive authentication error handling
- Improved error handling for Google Drive indexing and listing operations to manage authentication failures more effectively. - Added logic to mark connectors as 'auth_expired' when a 401 error or invalid credentials are detected, prompting users to re-authenticate. - Updated error messages to provide clearer guidance on authentication issues, ensuring a better user experience.
This commit is contained in:
parent
53e555f10c
commit
2390bd7d26
3 changed files with 35 additions and 1 deletions
|
|
@ -517,6 +517,7 @@ async def _index_full_scan(
|
|||
|
||||
# Queue of folders to process: (folder_id, folder_name)
|
||||
folders_to_process = [(folder_id, folder_name)]
|
||||
first_listing_error: str | None = None
|
||||
|
||||
logger.info("Phase 1: Collecting files and creating pending documents")
|
||||
|
||||
|
|
@ -536,6 +537,8 @@ async def _index_full_scan(
|
|||
|
||||
if error:
|
||||
logger.error(f"Error listing files in {current_folder_name}: {error}")
|
||||
if first_listing_error is None:
|
||||
first_listing_error = error
|
||||
break
|
||||
|
||||
if not files:
|
||||
|
|
@ -581,6 +584,15 @@ async def _index_full_scan(
|
|||
if not page_token:
|
||||
break
|
||||
|
||||
if not files_to_process and first_listing_error:
|
||||
error_lower = first_listing_error.lower()
|
||||
if "401" in first_listing_error or "invalid credentials" in error_lower or "authError" in first_listing_error:
|
||||
raise Exception(
|
||||
f"Google Drive authentication failed. Please re-authenticate. "
|
||||
f"(Error: {first_listing_error})"
|
||||
)
|
||||
raise Exception(f"Failed to list Google Drive files: {first_listing_error}")
|
||||
|
||||
# Commit all pending documents - they all appear in UI now
|
||||
if new_documents_created:
|
||||
logger.info(
|
||||
|
|
@ -666,7 +678,13 @@ async def _index_with_delta_sync(
|
|||
|
||||
if error:
|
||||
logger.error(f"Error fetching changes: {error}")
|
||||
return 0, 0
|
||||
error_lower = error.lower()
|
||||
if "401" in error or "invalid credentials" in error_lower or "authError" in error:
|
||||
raise Exception(
|
||||
f"Google Drive authentication failed. Please re-authenticate. "
|
||||
f"(Error: {error})"
|
||||
)
|
||||
raise Exception(f"Failed to fetch Google Drive changes: {error}")
|
||||
|
||||
if not changes:
|
||||
logger.info("No changes detected since last sync")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue