Skip to content

Commit

Permalink
Add RefreshError workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
felaube committed Jun 16, 2022
1 parent 6ee7661 commit 8d25243
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/main/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from google.auth.transport.requests import Request
from spreadsheet_handler import SpreadsheetHandler
from widget_gallery import WidgetGallery
import google.auth.exceptions as GoogleExceptions
from fbs_runtime.application_context.PyQt5 import ApplicationContext
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtGui import QIcon, QFont
Expand Down Expand Up @@ -59,9 +60,27 @@
# If there are no (valid) credentials available, let the user log in.
if not CREDS or not CREDS.valid:
if CREDS and CREDS.expired and CREDS.refresh_token:
CREDS.refresh(Request())
try:
CREDS.refresh(Request())
except GoogleExceptions.RefreshError:
error_message = "Your access token has expired. Please, complete the authentication flow once again, " + \
"accessing your google account on the website" + \
" that will be opened when you close this window."
print(error_message)
app = QApplication([])
error_window = QMessageBox()
error_window.setWindowTitle("Expenses Tracker")
error_window.setWindowIcon(QIcon(ApplicationContext().get_resource("submit.ico")))
error_window.setIcon(QMessageBox.Critical)
error_window.setText(error_message)
error_window.setStandardButtons(QMessageBox.Ok)
error_window.setDefaultButton(QMessageBox.Ok)
error_window.exec_()

flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
CREDS = flow.run_local_server(port=0)
else:
error_message = "Please complete the authentication flow " + \
error_message = "Please, complete the authentication flow " + \
"accessing your google account on the website" + \
" that will be opened when you close this window."
print(error_message)
Expand Down

0 comments on commit 8d25243

Please sign in to comment.