Merge pull request #16 from Codium-ai/bugfix/crash_protection

Add exception protection for unexpected conditions during request handling
This commit is contained in:
Ori Kotek
2023-07-06 19:54:55 +03:00
committed by GitHub

View File

@ -37,6 +37,7 @@ async def polling_loop():
raise ValueError("User token must be set to get notifications") raise ValueError("User token must be set to get notifications")
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
while True: while True:
try:
headers = { headers = {
"Accept": "application/vnd.github.v3+json", "Accept": "application/vnd.github.v3+json",
"Authorization": f"Bearer {token}" "Authorization": f"Bearer {token}"
@ -54,6 +55,8 @@ async def polling_loop():
last_modified[0] = response.headers['Last-Modified'] last_modified[0] = response.headers['Last-Modified']
since[0] = None since[0] = None
notifications = await response.json() notifications = await response.json()
if not notifications:
continue
for notification in notifications: for notification in notifications:
if 'id' in notification and notification['id'] in handled_ids: if 'id' in notification and notification['id'] in handled_ids:
continue continue
@ -81,6 +84,9 @@ async def polling_loop():
print(f"Failed to fetch notifications. Status code: {response.status}") print(f"Failed to fetch notifications. Status code: {response.status}")
await asyncio.sleep(5) await asyncio.sleep(5)
except Exception as e:
logging.error(f"Exception during processing of a notification: {e}")
await asyncio.sleep(5)
if __name__ == '__main__': if __name__ == '__main__':
asyncio.run(polling_loop()) asyncio.run(polling_loop())