From da95d83be5a3619d4e05a41972f075d3485abc8e Mon Sep 17 00:00:00 2001 From: tazlin Date: Tue, 6 Jun 2023 21:06:55 -0400 Subject: [PATCH] fix: handle `get_all_models()`'s requests.get call to github if network problems occur (#248) --- worker/bridge_data/stable_diffusion.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/worker/bridge_data/stable_diffusion.py b/worker/bridge_data/stable_diffusion.py index 60f4aea6..8a78aeb3 100644 --- a/worker/bridge_data/stable_diffusion.py +++ b/worker/bridge_data/stable_diffusion.py @@ -180,9 +180,18 @@ def get_all_models(self, style=""): return self._all_model_names[:] logger.info("Refreshing the list of all available models") - data = requests.get( - "https://raw.githubusercontent.com/Haidra-Org/AI-Horde-image-model-reference/main/stable_diffusion.json", - ).json() + response = None + try: + response = requests.get( + url="https://raw.githubusercontent.com/Haidra-Org/AI-Horde-image-model-reference/main/stable_diffusion.json", + timeout=10, + ) + response.raise_for_status() + except (requests.exceptions.RequestException, requests.exceptions.HTTPError) as e: + logger.error(f"Failed to retrieve the list of all available models: {e}") + return self.models_to_load if self.models_to_load else [] + + data = response.json() # Get all interesting models models = []