Skip to content

Commit

Permalink
Improved CloudFlare error handling (close #258)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Dec 3, 2020
1 parent 476123b commit ba799d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,18 +509,21 @@ def parse_cf_id(self, url, bulk=False, reverse=False):
if slug in self.cfIDs:
project = self.cfIDs[slug]
else:
payload = self.scraper.get(url + '/download-client')
if payload.status_code == 404:
renamecheck = self.scraper.get(url, allow_redirects=False)
if renamecheck.status_code == 303:
payload = self.scraper.get(f'https://www.curseforge.com{renamecheck.headers["location"]}'
f'/download-client')
try:
payload = self.scraper.get(url + '/download-client')
if payload.status_code == 404:
if bulk:
return 0
else:
raise RuntimeError(f'{slug}\nThe project could be removed from CurseForge or renamed. Uninstall'
f' it (and reinstall if it still exists) to fix this issue.')
renamecheck = self.scraper.get(url, allow_redirects=False)
if renamecheck.status_code == 303:
payload = self.scraper.get(f'https://www.curseforge.com{renamecheck.headers["location"]}'
f'/download-client')
if payload.status_code == 404:
if bulk:
return 0
else:
raise RuntimeError(f'{slug}\nThe project could be removed from CurseForge or renamed. Unins'
f'tall it (and reinstall if it still exists) to fix this issue.')
except cloudscraper.CloudflareChallengeError:
return 0
xml = parseString(payload.text)
project = xml.childNodes[0].getElementsByTagName('project')[0].getAttribute('id')
self.config['CFCacheCloudFlare'][slug] = project
Expand Down
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
from rich.terminal_theme import TerminalTheme

__version__ = '3.15.3'
__version__ = '3.15.4'
__license__ = 'GPLv3'
__copyright__ = '2019-2020, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down

0 comments on commit ba799d0

Please sign in to comment.