From 91b3a7d2ce97112276db5673e9fcebb57b7d1bf2 Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Fri, 25 Sep 2020 13:38:36 +0200
Subject: [PATCH] Don't treat a 404 as a fatal error

---
 src/api/fanart_api.js | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/api/fanart_api.js b/src/api/fanart_api.js
index 75f7258..7576a4a 100644
--- a/src/api/fanart_api.js
+++ b/src/api/fanart_api.js
@@ -19,18 +19,26 @@ class FanartApi {
                 timeout: 2000,
             },
         }).then((response) => {
-            return response.text().then(text => {
-                return {
-                    ok: response.ok,
-                    body: text,
-                }
-            });
+            if (response.status === 404) {
+                return null;
+            } else {
+                return response.text().then(text => {
+                    return {
+                        ok: response.ok,
+                        body: text,
+                    }
+                });
+            }
         }).then((data) => {
-            const {ok, body} = data;
-            if (!ok) {
-                throw new Error(`${url}: ${body}`);
+            if (data === null) {
+                return null;
+            } else {
+                const {ok, body} = data;
+                if (!ok) {
+                    throw new Error(`${url}: ${body}`);
+                }
+                return JSON.parse(body);
             }
-            return JSON.parse(body);
         }).catch(err => {
             console.error(err);
             return null;
-- 
GitLab