diff --git a/CB/CurseForge.py b/CB/CurseForge.py index 5d60a87..b6d21d5 100644 --- a/CB/CurseForge.py +++ b/CB/CurseForge.py @@ -4,6 +4,7 @@ import requests from . import retry, HEADERS from operator import itemgetter +from json import JSONDecodeError class CurseForgeAddon: @@ -14,7 +15,7 @@ def __init__(self, url, project, checkcache, clienttype, allowdev): else: self.payload = requests.get(f'https://addons-ecs.forgesvc.net/api/v2/addon/{project}', headers=HEADERS) - if self.payload.status_code == 404: + if self.payload.status_code == 404 or self.payload.status_code == 500: raise RuntimeError(f'{url}\nThis might be a temporary issue with CurseForge API or the project was ' f'removed/renamed. In this case, uninstall it (and reinstall if it still exists) ' f'to fix this issue.') @@ -22,7 +23,10 @@ def __init__(self, url, project, checkcache, clienttype, allowdev): raise RuntimeError(f'{url}\nAccess to CurseForge API was blocked. It is most likely caused by your' f' ISP or internet filter implemented by your government.') else: - self.payload = self.payload.json() + try: + self.payload = self.payload.json() + except (StopIteration, JSONDecodeError): + raise RuntimeError(f'{url}\nThis might be a temporary issue with CurseForge API.') self.name = self.payload['name'].strip().strip('\u200b') if not len(self.payload['latestFiles']) > 0: raise RuntimeError(f'{self.name}.\nThe project doesn\'t have any releases.')