aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-03-22 19:18:57 +0100
committerGravatar kwzrd <[email protected]>2020-03-22 19:18:57 +0100
commit76fa63cab48f52e8be6d8dcdb079709e2d755641 (patch)
tree6103e01f1c99d3ebc36925c43a600c7a660ede70
parentDeseasonify: improve response messages (diff)
Deseasonify: short-circuit on non-200 response status
If Github API responds with a non-200 status, we simply return an empty dict. This is a safe value - the `refresh` function will handle this as if the directory was empty.
-rw-r--r--bot/branding.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/bot/branding.py b/bot/branding.py
index 9b5d96e3..9e006d99 100644
--- a/bot/branding.py
+++ b/bot/branding.py
@@ -18,6 +18,8 @@ from bot.seasons import SeasonBase, get_current_season, get_season
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
+STATUS_OK = 200 # HTTP status code
+
FILE_BANNER = "banner.png"
FILE_AVATAR = "avatar.png"
SERVER_ICONS = "server_icons"
@@ -198,10 +200,16 @@ class BrandingManager(commands.Cog):
Poll `path` in branding repo for information about present files.
Return dict mapping from filename to corresponding `GithubFile` instance.
+ This may return an empty dict if the response status is non-200,
+ or if the target directory is empty.
"""
url = f"{BRANDING_URL}/{path}"
async with self.bot.http_session.get(url, headers=HEADERS, params=PARAMS) as resp:
- directory = await resp.json()
+ # Short-circuit if we get non-200 response
+ if resp.status != STATUS_OK:
+ log.error(f"Github API returned non-200 response: {resp}")
+ return {}
+ directory = await resp.json() # Directory at `path`
return {
file["name"]: GithubFile(file["download_url"], file["path"], file["sha"])