From e9168f917e49829ab1e327bfbd7b868933e63077 Mon Sep 17 00:00:00 2001 From: Teknium Date: Thu, 9 Apr 2026 14:22:17 -0700 Subject: [PATCH] fix: handle HTTP errors gracefully in gws_bridge token refresh Instead of crashing with a raw urllib traceback on refresh failure, print a clean error message and suggest re-running setup.py. --- .../google-workspace/scripts/gws_bridge.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/skills/productivity/google-workspace/scripts/gws_bridge.py b/skills/productivity/google-workspace/scripts/gws_bridge.py index 7ee74fc97..adecd33ad 100755 --- a/skills/productivity/google-workspace/scripts/gws_bridge.py +++ b/skills/productivity/google-workspace/scripts/gws_bridge.py @@ -21,6 +21,7 @@ def get_token_path() -> Path: def refresh_token(token_data: dict) -> dict: """Refresh the access token using the refresh token.""" + import urllib.error import urllib.parse import urllib.request @@ -32,8 +33,14 @@ def refresh_token(token_data: dict) -> dict: }).encode() req = urllib.request.Request(token_data["token_uri"], data=params) - with urllib.request.urlopen(req) as resp: - result = json.loads(resp.read()) + try: + with urllib.request.urlopen(req) as resp: + result = json.loads(resp.read()) + except urllib.error.HTTPError as e: + body = e.read().decode("utf-8", errors="replace") + print(f"ERROR: Token refresh failed (HTTP {e.code}): {body}", file=sys.stderr) + print("Re-run setup.py to re-authenticate.", file=sys.stderr) + sys.exit(1) token_data["token"] = result["access_token"] token_data["expiry"] = datetime.fromtimestamp(