Handle KeyErrors in __parse_headers. Closes #9

This commit is contained in:
agatha 2023-11-11 15:33:18 -05:00
parent e4a153d385
commit 1e958b397a

View File

@ -72,9 +72,12 @@ class GitHubApi:
headers (dict): The response headers from the GitHub API.
"""
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
self.rate_remaining = int(headers['x-ratelimit-remaining'])
logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})')
try:
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
self.rate_remaining = int(headers['x-ratelimit-remaining'])
logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})')
except KeyError as e:
logger.warning(f'Could not parse headers: {str(e)}')
def get_events(self, page=None):
"""Fetch GitHub events.