Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated error message if the token has expired #62

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion google_sheets/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
from fastapi import Body, FastAPI, HTTPException, Query, Response, status
from fastapi.responses import RedirectResponse
from google.auth.exceptions import RefreshError
from googleapiclient.errors import HttpError

from . import __version__
Expand Down Expand Up @@ -263,7 +264,17 @@ async def get_all_file_names(
],
) -> Dict[str, str]:
service = await build_service(user_id=user_id, service_name="drive", version="v3")
files: List[Dict[str, str]] = await get_files_f(service=service)
try:
files: List[Dict[str, str]] = await get_files_f(service=service)
except RefreshError as e:
error_msg = "The user's credentials have expired. Please log in again with 'force_new_login' parameter set to 'True'.\n"
error_msg += f"Error: {e!s}"

raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail=error_msg
) from e
except Exception as e:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) from e
# create dict where key is id and value is name
files_dict = {file["id"]: file["name"] for file in files}
return files_dict
Expand Down
Loading