From 1ffc1b57f21ab472bb60433792a448b829853e32 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 23 Oct 2022 10:30:52 -0700 Subject: [PATCH] Catch cache errors --- src/components/Timeline.vue | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 5e4590fd..9a82ef53 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -556,14 +556,21 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) { data = await dav.getPeopleData(); } else { // Try the cache - cache = noCache ? null : (await utils.getCachedData(cacheUrl)); - if (cache) { - await this.processDays(cache); - this.loading--; + try { + cache = noCache ? null : (await utils.getCachedData(cacheUrl)); + if (cache) { + await this.processDays(cache); + this.loading--; + } + } catch { + console.warn(`Failed to process days cache: ${cacheUrl}`); + cache = null; } // Get from network - data = (await axios.get(url)).data; + const res = await axios.get(url); + if (res.status !== 200) throw res; // don't cache this + data = res.data; } // Put back into cache @@ -704,7 +711,12 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) { this.sizedDays.add(dayId); // Look for cache - this.processDay(dayId, await utils.getCachedData(this.getDayUrl(dayId))); + const cacheUrl = this.getDayUrl(dayId); + try { + this.processDay(dayId, await utils.getCachedData(cacheUrl)); + } catch { + console.warn(`Failed to process day cache: ${cacheUrl}`); + } // Aggregate fetch requests this.fetchDayQueue.push(dayId); @@ -726,6 +738,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) { try { const startState = this.state; const res = await axios.get(url); + if (res.status !== 200) throw res; const data = res.data; if (this.state !== startState) return;