diff options
author | 2024-08-15 00:48:24 +0100 | |
---|---|---|
committer | 2024-08-15 00:48:24 +0100 | |
commit | dfe9e9f1020749e394f7b0357788a235563929df (patch) | |
tree | 567321b539d67b929ce00894a113a109fab77831 /pydis_site/apps | |
parent | Merge pull request #1411 from python-discord/dependabot/pip/django-filter-24.3 (diff) |
Harden GitHub metadata fetch on homepage
Diffstat (limited to 'pydis_site/apps')
-rw-r--r-- | pydis_site/apps/home/views.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/pydis_site/apps/home/views.py b/pydis_site/apps/home/views.py index 71f95293..0df84478 100644 --- a/pydis_site/apps/home/views.py +++ b/pydis_site/apps/home/views.py @@ -1,4 +1,5 @@ import logging +from json.decoder import JSONDecodeError import httpx from django.core.handlers.wsgi import WSGIRequest @@ -53,14 +54,24 @@ class HomeView(View): repo_dict = {} try: # Fetch the data from the GitHub API - api_data: list[dict] = httpx.get( + resp = httpx.get( self.github_api, headers=self.headers, timeout=settings.TIMEOUT_PERIOD - ).json() + ) + + resp.raise_for_status() + + api_data: list[dict] = resp.json() except httpx.TimeoutException: log.error("Request to fetch GitHub repository metadata for timed out!") return repo_dict + except httpx.HTTPStatusError as ex: + log.error(f"Received HTTP {ex.response.status_code} from GitHub repository metadata request!") + return repo_dict + except JSONDecodeError: + log.error("GitHub returned invalid JSON for repository metadata!") + return repo_dict # Process the API data into our dict for repo in api_data: |