do not fail if cache missed

This commit is contained in:
Hongbo Wu
2024-05-17 17:27:34 +08:00
parent 6f2aa2e0cd
commit fc9d5c64ec

View File

@ -103,16 +103,17 @@ export const cacheFetchResult = async (
const getCachedFetchResult = async (
key: string
): Promise<FetchResult | null> => {
): Promise<FetchResult | undefined> => {
const result = await redisDataSource.cacheClient.get(key)
if (!result) {
console.info('fetch result is not cached', key)
return null
return undefined
}
const fetchResult = JSON.parse(result) as unknown
if (!isFetchResult(fetchResult)) {
throw new Error('fetch result is not valid')
console.error('invalid fetch result in cache', key)
return undefined
}
console.info('fetch result is cached', key)