diff --git a/src/api/fanart_api.js b/src/api/fanart_api.js index 75f7258f2381cb7f9a16da8bea120f3d2d0241cb..7576a4a4c976bf3866f994dad3ea2694c53ad413 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;