Skip to content

Commit

Permalink
Handling error ig
Browse files Browse the repository at this point in the history
  • Loading branch information
TechiError committed Jan 1, 2024
1 parent bed02e4 commit dfe5f64
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bot/onedrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def get_access_token(self, code: str = None):
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=data,
) as resp:
expiry_time = self.creds["expires_in"]
expiry_time = self.creds.get("expires_in")
self.creds = await resp.json()
self.creds["expires_at"] = time.time() + expiry_time
udB.set_key("OD_AUTH_TOKEN", self.creds)
Expand All @@ -117,14 +117,18 @@ async def refresh_access_token(self):
) as resp:
expiry_time = self.creds["expires_in"]
self.creds = await resp.json()
if self.creds.get("error"):
return self.creds
self.creds["expires_at"] = time.time() + expiry_time
await resp.release()
udB.set_key("OD_AUTH_TOKEN", self.creds)
return

async def get_headers(self):
if self.creds.get("expires_at", 0) < time.time():
await self.refresh_access_token()
error = await self.refresh_access_token()
if error:
return error
return {
"Authorization": f"Bearer {self.creds['access_token']}",
"Content-Type": "application/json",
Expand Down

0 comments on commit dfe5f64

Please sign in to comment.