diff options
author | mat <github@matdoes.dev> | 2022-06-01 18:49:59 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-06-01 18:49:59 -0500 |
commit | 89c7f563a3e41ab2efda37726f6ad99f30d9ec41 (patch) | |
tree | 0104fefb9b8ab79a98edeff912007fb04340bc34 /src | |
parent | 8fff4f98541ecda20146d9a432aba276ebc81bcc (diff) | |
download | skyblock-api-89c7f563a3e41ab2efda37726f6ad99f30d9ec41.tar.gz skyblock-api-89c7f563a3e41ab2efda37726f6ad99f30d9ec41.tar.bz2 skyblock-api-89c7f563a3e41ab2efda37726f6ad99f30d9ec41.zip |
Fix hanging on errors in withCache
Diffstat (limited to 'src')
-rw-r--r-- | src/util.ts | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/util.ts b/src/util.ts index 9af95c7..f50118b 100644 --- a/src/util.ts +++ b/src/util.ts @@ -132,7 +132,14 @@ export async function withCache<T>(key: string, ttl: number | ((arg: T) => Date) ...(caches.get(key) ?? { data: undefined, nextUpdate: new Date(0) }), isFetching: true, }) - const data = await task() + const data = await task().catch(e => { + console.error(e) + caches.set(key, { + ...(caches.get(key) ?? { data: undefined, nextUpdate: new Date(0) }), + isFetching: false, + }) + return undefined + }) caches.set(key, { ...caches.get(key)!, isFetching: false, |