From ee618431838da5f0e59e32b3396ba280f9147c88 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 30 Jun 2020 16:26:01 +0100 Subject: [PATCH] Catch JSON error and retry --- app.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index dd250cf..61b222a 100755 --- a/app.py +++ b/app.py @@ -799,9 +799,13 @@ def get_image_detail_with_cache(items, cache_name, thumbwidth=None, refresh=Fals filename = f'cache/{cache_name}_images.json' cache_exists = os.path.exists(filename) + detail = None if not refresh and cache_exists: - detail = json.load(open(filename)) - else: + try: + detail = json.load(open(filename)) + except json.decoder.JSONDecodeError: + pass + if not detail: try: detail = commons.image_detail(filenames, thumbwidth=thumbwidth) json.dump(detail, open(filename, 'w'), indent=2)