Skip to content

Commit

Permalink
Improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Aug 13, 2020
1 parent c03752a commit c6d7064
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CB/CurseForge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
from . import retry, HEADERS
from operator import itemgetter
from json import JSONDecodeError


class CurseForgeAddon:
Expand All @@ -14,15 +15,18 @@ 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.')
elif self.payload.status_code == 403:
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.')
Expand Down

0 comments on commit c6d7064

Please sign in to comment.