Skip to content

Commit

Permalink
refactor(core): add trySafe to wellknown cache
Browse files Browse the repository at this point in the history
add trySafe to wellknown cache
  • Loading branch information
simeng-li committed Nov 20, 2024
1 parent ffb789d commit 094d897
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/core/src/caches/well-known.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ export class WellKnownCache {

/**
* Get value from the inner cache store for the given type and key.
* Note: Format errors will be silently caught and result an `undefined` return.
* Note: Redis connection and format errors will be silently caught and result an `undefined` return.
*/
async get<Type extends WellKnownCacheType>(
type: Type,
key: string
): Promise<Optional<WellKnownMap[Type]>> {
const data = await this.cacheStore.get(this.cacheKey(type, key));

return trySafe(() => getValueGuard(type).parse(JSON.parse(data ?? '')));
return trySafe(async () => {
const data = await this.cacheStore.get(this.cacheKey(type, key));
return getValueGuard(type).parse(JSON.parse(data ?? ''));
});
}

/**
Expand Down

0 comments on commit 094d897

Please sign in to comment.