diff --git a/SAS/TMSS/backend/services/windmill_standstill/lib/windmill_standstill.py b/SAS/TMSS/backend/services/windmill_standstill/lib/windmill_standstill.py index 548e86f1651b29e1b316fb0ed6de4e87356d93b2..f442015ecd9590de08d33bbcedef02794c6a8c20 100644 --- a/SAS/TMSS/backend/services/windmill_standstill/lib/windmill_standstill.py +++ b/SAS/TMSS/backend/services/windmill_standstill/lib/windmill_standstill.py @@ -71,16 +71,23 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler): self.polling_thread.join() def refresh_access_token(self): - logger.info('refreshing access token...') - response = requests.post(self.token_url, - data={"grant_type": "client_credentials", - "scope": self.scope, - "client_id": self.client_id, - "client_secret": self.client_secret}) - json_response = response.json() - self.access_token = json_response["access_token"] - self.access_token_expiration_date = datetime.utcnow() + timedelta(seconds=json_response['expires_in']-10) - logger.info('new token valid till %s' % self.access_token_expiration_date.isoformat()) + try: + logger.info('refreshing access token...') + response = requests.post(self.token_url, + data={"grant_type": "client_credentials", + "scope": self.scope, + "client_id": self.client_id, + "client_secret": self.client_secret}) + except Exception as e: + logger.error("could not refresh access token: %s", str(e)) + + try: + json_response = response.json() + self.access_token = json_response["access_token"] + self.access_token_expiration_date = datetime.utcnow() + timedelta(seconds=json_response['expires_in']-10) + logger.info('new token valid till %s' % self.access_token_expiration_date.isoformat()) + except Exception as e: + logger.error("could not refresh access token: http_status_code=%s error: %s", response.status_code, str(e)) def get_api_path_as_json(self, path): if datetime.utcnow() >= self.access_token_expiration_date: