From 414cdf7c387335c0650008f01fd54e706b1b402e Mon Sep 17 00:00:00 2001 From: Matt Black Date: Mon, 8 Jul 2024 14:46:12 +1000 Subject: [PATCH] Raise an exception when the oauth flow fails --- gcsa/_services/authentication.py | 5 +++++ gcsa/exceptions.py | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 gcsa/exceptions.py diff --git a/gcsa/_services/authentication.py b/gcsa/_services/authentication.py index 27dd00b..b43c15d 100644 --- a/gcsa/_services/authentication.py +++ b/gcsa/_services/authentication.py @@ -9,6 +9,8 @@ from google.auth.transport.requests import Request from google.auth.credentials import Credentials +from gcsa.exceptions import FailedToAuthenticateError + class AuthenticatedService: """Handles authentication of the `GoogleCalendar`""" @@ -123,6 +125,9 @@ def _get_credentials( except WSGITimeout: print('Authentication flow timed out. Please try again.') + if credentials is None: + raise FailedToAuthenticateError + if save_token: with open(token_path, 'wb') as token_file: pickle.dump(credentials, token_file) diff --git a/gcsa/exceptions.py b/gcsa/exceptions.py new file mode 100644 index 0000000..1e9675a --- /dev/null +++ b/gcsa/exceptions.py @@ -0,0 +1,2 @@ +class FailedToAuthenticateError(Exception): + pass