diff --git a/database.py b/database.py index 62cbb7b9..3803d54a 100644 --- a/database.py +++ b/database.py @@ -124,7 +124,16 @@ async def update_lol(discord_id): account.summoner_name = data["name"] account.level = data["summonerLevel"] # Poll the League API for ranked data - soloq, flexq, ttq = await lol.get_rank_data("euw", lid) + try: + soloq, flexq, ttq = await lol.get_rank_data("euw", lid) + except lol.LoLAPIError as e: + if e.status_code == 404: + account.soloq_tier = None + account.soloq_division = None + account.flexq_tier = None + account.flexq_division = None + account.ttq_tier = None + account.ttq_division = None # Update the user data if soloq is not None: account.soloq_tier = lol.tiers.index(soloq["tier"]) diff --git a/lol.py b/lol.py index a826ce31..9547fc20 100644 --- a/lol.py +++ b/lol.py @@ -5,7 +5,9 @@ import royalbotconfig # https://euw.api.riotgames.com/api/lol/EUW/v1.4/summoner/52348350?api_key=RGAPI-1008c33d-b0a4-4091-8600-27022d570964 class LoLAPIError(Exception): - pass + def __init__(self, status_code, text): + self.status_code = status_code + self.text = text tiers = ["BRONZE", "SILVER", "GOLD", "PLATINUM", "DIAMOND", "MASTER", "CHALLENGER"] @@ -19,7 +21,7 @@ async def get_json(url, **kwargs): async with session.get(url, **kwargs) as response: json = await response.json() if response.status != 200: - raise LoLAPIError(f"Riot API returned {response.status}") + raise LoLAPIError(response.status, f"Riot API returned {response.status}") return json