diff --git a/src/home/fetch-github/fetch-and-display-previews.ts b/src/home/fetch-github/fetch-and-display-previews.ts index 4dfc9b6c..4b33bd8a 100644 --- a/src/home/fetch-github/fetch-and-display-previews.ts +++ b/src/home/fetch-github/fetch-and-display-previews.ts @@ -31,24 +31,27 @@ export async function fetchAndDisplayPreviewsFromCache(sorting?: Sorting, option return fetchAndDisplayPreviewsFromNetwork(sorting, options); } - // makes sure tasks have a timestamp to know how old the cache is, or refresh if older than 15 minutes - if (!_cachedTasks || !_cachedTasks.timestamp || _cachedTasks.timestamp + 60 * 1000 * 15 <= Date.now()) { - _cachedTasks = { - timestamp: Date.now(), - tasks: [], - loggedIn: _accessToken !== null, - }; - } - - const cachedTasks = _cachedTasks.tasks as TaskMaybeFull[]; - taskManager.syncTasks(cachedTasks); + try { + // makes sure tasks have a timestamp to know how old the cache is, or refresh if older than 15 minutes + if (!_cachedTasks || !_cachedTasks.timestamp || _cachedTasks.timestamp + 60 * 1000 * 15 <= Date.now()) { + _cachedTasks = { + timestamp: Date.now(), + tasks: [], + loggedIn: _accessToken !== null, + }; + } + const cachedTasks = _cachedTasks.tasks as TaskMaybeFull[]; + taskManager.syncTasks(cachedTasks); - if (!cachedTasks.length) { - // load from network if there are no cached issues + if (!cachedTasks.length) { + // load from network if there are no cached issues + return fetchAndDisplayPreviewsFromNetwork(sorting, options); + } else { + displayGitHubIssues(sorting, options); + return fetchAvatars(); + } + } catch (cacheError) { return fetchAndDisplayPreviewsFromNetwork(sorting, options); - } else { - displayGitHubIssues(sorting, options); - return fetchAvatars(); } }