Skip to content

Commit

Permalink
Updated error message if the token has expired (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjambrecic authored Jul 25, 2024
1 parent 2b3a4cd commit 1ada8d5
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 1ada8d5

Please sign in to comment.