Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
fix(cache): add caching error handling (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alezco authored Jan 13, 2021
1 parent 1e3917c commit 30b2a6a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/caching/caching-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export const createCache = <T>(
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();
Expand Down

0 comments on commit 30b2a6a

Please sign in to comment.