From 1e958b397a56e4827e6ac6d87ec58116a1f25a56 Mon Sep 17 00:00:00 2001 From: agatha Date: Sat, 11 Nov 2023 15:33:18 -0500 Subject: [PATCH] Handle KeyErrors in __parse_headers. Closes #9 --- gitmon/api.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gitmon/api.py b/gitmon/api.py index 79b5e10..0cb5f00 100644 --- a/gitmon/api.py +++ b/gitmon/api.py @@ -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.