From 74a1486f0eb6fb5253256770cf35a8723106d1ef Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 18 Dec 2024 17:32:00 -0700 Subject: [PATCH] Hiding syntax errors when API is down. --- app/src/Events.js | 5 ++++- app/src/Tags.js | 5 ++++- app/src/api.js | 6 ++++-- app/src/hooks/customHooks.js | 12 +++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/Events.js b/app/src/Events.js index 0aa66f35..76706d62 100644 --- a/app/src/Events.js +++ b/app/src/Events.js @@ -114,7 +114,10 @@ export function useEventsInterval() { setEvents(response['events']); } catch (e) { setEvents(null); - console.error(e); + // Ignore SyntaxError because they happen when the API is down. + if (!(e instanceof SyntaxError)) { + console.error(e); + } } } diff --git a/app/src/Tags.js b/app/src/Tags.js index 19522371..33fd2858 100644 --- a/app/src/Tags.js +++ b/app/src/Tags.js @@ -48,7 +48,10 @@ export function useTags() { } catch (e) { setTags(undefined); setTagNames(undefined); - console.error(e); + // Ignore SyntaxError because they happen when the API is down. + if (!(e instanceof SyntaxError)) { + console.error(e); + } } } diff --git a/app/src/api.js b/app/src/api.js index 26a1e833..4243aee1 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -51,8 +51,10 @@ async function apiCall(url, method, body, ms = 60_000) { } return response; } catch (e) { - // Timeout, or some other exception. - console.error(e); + // Ignore SyntaxError because they happen when the API is down. + if (!(e instanceof SyntaxError)) { + console.error(e); + } throw e; } } diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js index acf297ae..e2bcc34b 100644 --- a/app/src/hooks/customHooks.js +++ b/app/src/hooks/customHooks.js @@ -18,8 +18,8 @@ import { getStatus, getVideo, getVideosStatistics, - postImportConfig, postDumpConfig, + postImportConfig, saveSettings, searchArchives, searchChannels, @@ -705,7 +705,10 @@ export const useConfigs = () => { setConfigs(data['configs']); console.debug('fetching configs successful'); } catch (e) { - console.error(e); + // Ignore SyntaxError because they happen when the API is down. + if (!(e instanceof SyntaxError)) { + console.error(e); + } setConfigs(undefined); } finally { setLoading(false); @@ -840,7 +843,10 @@ export const useStatus = () => { const s = await getStatus(); setStatus(s); } catch (e) { - console.error(e); + // Ignore SyntaxError because they happen when the API is down. + if (!(e instanceof SyntaxError)) { + console.error(e); + } } }