Skip to content

Commit db068a0

Browse files
Niloth-ptimabbott
authored andcommitted
google-calendar: Add error handling for missing client secret file.
1 parent 4dddd87 commit db068a0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

zulip/integrations/google/get-google-credentials

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
2+
import logging
23
import os
4+
import sys
35

46
from google.auth.transport.requests import Request
57
from google.oauth2.credentials import Credentials
@@ -40,9 +42,14 @@ def get_credentials() -> Credentials:
4042
if creds and creds.expired and creds.refresh_token:
4143
creds.refresh(Request())
4244
else:
43-
flow = InstalledAppFlow.from_client_secrets_file(
44-
os.path.join(HOME_DIR, CLIENT_SECRET_FILE), SCOPES
45-
)
45+
client_secret_path = os.path.join(HOME_DIR, CLIENT_SECRET_FILE)
46+
if not os.path.exists(client_secret_path):
47+
logging.error(
48+
"Unable to find the client secret file. Please ensure that you have downloaded the client secret file from Google, and placed it at %s.",
49+
client_secret_path,
50+
)
51+
sys.exit(1)
52+
flow = InstalledAppFlow.from_client_secrets_file(client_secret_path, SCOPES)
4653
creds = flow.run_local_server(port=0)
4754
with open(tokens_path, "w") as token:
4855
token.write(creds.to_json())

0 commit comments

Comments
 (0)