From d5f73c226c87626e295d9939195d763a924d6f84 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sat, 17 Aug 2024 11:26:01 +1000 Subject: [PATCH] GoogleAPIClient: Improve error reporting --- common/common/googleapis.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/common/googleapis.py b/common/common/googleapis.py index 09408de..95a86ab 100644 --- a/common/common/googleapis.py +++ b/common/common/googleapis.py @@ -3,6 +3,7 @@ import time import logging import gevent +from requests import HTTPError from .requests import InstrumentedSession @@ -56,11 +57,13 @@ class GoogleAPIClient(object): expires_in, self.ACCESS_TOKEN_REFRESH_TIME_BEFORE_EXPIRY, )) gevent.spawn_later(expires_in - self.ACCESS_TOKEN_REFRESH_TIME_BEFORE_EXPIRY, self.get_access_token) + except HTTPError as e: + logging.error(f"Failed to fetch access token with {e.response.status_code}, retrying: {e.response.content}") except Exception: logging.exception("Failed to fetch access token, retrying") - gevent.sleep(self.ACCESS_TOKEN_ERROR_RETRY_INTERVAL) else: break + gevent.sleep(self.ACCESS_TOKEN_ERROR_RETRY_INTERVAL) def request(self, method, url, headers={}, **kwargs): # merge in auth header