Self hosted FLOSS fitness/workout, nutrition and weight tracker
Catch JSONDecodeError when loading ingredients from OFF
Roland Geider37c3e257605d
diff --git a/wger/nutrition/models/ingredient.py b/wger/nutrition/models/ingredient.pyindex ea659ce5e..f98d71fcc 100644--- a/wger/nutrition/models/ingredient.py+++ b/wger/nutrition/models/ingredient.py@@ -18,6 +18,7 @@import loggingimport uuid as uuidfrom decimal import Decimal+from json import JSONDecodeError# Djangofrom django.conf import settings@@ -461,7 +462,12 @@ class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):# wgerfrom wger.nutrition.off import extract_info_from_off- result = openfoodfacts.products.get_product(code)+ logger.info(f'Searching for ingredient {code} in OFF')+ try:+ result = openfoodfacts.products.get_product(code)+ except JSONDecodeError:+ logger.info('Got JSONDecodeError from OFF')+ return Noneif result['status'] != OFF_SEARCH_PRODUCT_FOUND:return Noneproduct = result['product']@@ -479,4 +485,5 @@ class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):ingredient = cls(**ingredient_data)ingredient.save()+ logger.info(f'Ingredient found and saved to local database: {ingredient.uuid}')return ingredient