Azure: log authentication errors

If we receive an authentication error from Azure, raise it as
a structured exception so that we will log the error message.

Change-Id: I37de2b11d82d678871c6186c3da4f5c9070f6f07
This commit is contained in:
James E. Blair 2023-03-13 10:49:51 -07:00
parent ccb530a166
commit 3f699f9455
1 changed files with 9 additions and 2 deletions

View File

@ -40,8 +40,15 @@ class AzureAuth(requests.auth.AuthBase):
}
r = requests.post(url, data)
ret = r.json()
self.token = ret['access_token']
self.expiration = float(ret['expires_on'])
if 'access_token' in ret:
self.token = ret['access_token']
self.expiration = float(ret['expires_on'])
elif ('error_codes' in ret and 'error_description' in ret):
raise AzureError(r.status_code,
ret['error_codes'][0],
ret['error_description'])
else:
raise Exception("Unknown error when authenticating to Azure")
def __call__(self, r):
self.refresh()