From 30b2a6a4c089e56e861c985e33b421c4c8423ccf Mon Sep 17 00:00:00 2001 From: Benjamin Morali Date: Wed, 13 Jan 2021 17:33:09 +0100 Subject: [PATCH] fix(cache): add caching error handling (#23) --- src/caching/caching-service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/caching/caching-service.ts b/src/caching/caching-service.ts index 74abcbc..f5fdeb8 100644 --- a/src/caching/caching-service.ts +++ b/src/caching/caching-service.ts @@ -15,8 +15,12 @@ export const createCache = ( let refreshTimeout: NodeJS.Timeout | null = null; const refresh = async () => { refreshTimeout?.unref(); - cacheData = await fetchData(); - lastFetchTimestamp = Date.now(); + try { + cacheData = await fetchData(); + lastFetchTimestamp = Date.now(); + } catch (error: unknown) { + console.error(error); + } refreshTimeout = setTimeout(() => void refresh(), ttl); }; void refresh();