Skip to content

Commit

Permalink
fix: prevent errors when thunderstore request fails
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Jan 4, 2024
1 parent 2718c44 commit f20107d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/decompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def mods_file_path(community: str):

def fetch_mods(community: str, file_lock: RWLockRead):
logging.info(f"Fetching Thunderstore for {community} ...")
thunder_mods = thunderstore.fetch_online(community)
success, thunder_mods = thunderstore.fetch_online(community)

if not success:
return

write_lock = file_lock.gen_rlock()
read_lock = file_lock.gen_rlock()
decompiled_mods = read_extracted_mod_from_file(community, read_lock)
Expand Down
2 changes: 1 addition & 1 deletion src/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def fetch_mods(self):
def update_mod_list(self, game: config.GameConfig):
if not env.DECOMPILE_THUNDERSTORE_MODS:
logging.info(f"Fetching Thunderstore for {game.name} ...")
thunder_mods = thunderstore.fetch_online(game.thunderstore.community)
success, thunder_mods = thunderstore.fetch_online(game.thunderstore.community)
else:
thunder_mods = []

Expand Down
8 changes: 7 additions & 1 deletion src/thunderstore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import logging

import app_version

Expand All @@ -10,7 +11,12 @@

def fetch_online(community: str):
r = requests.get(f"https://{community}.thunderstore.io/api/v1/package/", headers={**default_headers})
return r.json()

if r.status_code == 200:
return True, r.json()

logging.info(f"Thunderstore package request failed with status code {r.status_code}")
return False, []


def download_mod(download_url: str):
Expand Down

0 comments on commit f20107d

Please sign in to comment.