Fix errors when postgres returns undefined and trying to save to redis

This commit is contained in:
Ajay 2024-09-13 14:36:52 -04:00
parent 6edd71194b
commit dc5158257e

View file

@ -21,7 +21,8 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
const data = await fetchFromDB();
redis.setExWithCache(key, config.redis?.expiryTime, JSON.stringify(data)).catch((err) => Logger.error(err));
// Undefined can't be stringified, but null can
redis.setExWithCache(key, config.redis?.expiryTime, JSON.stringify(data ?? null)).catch((err) => Logger.error(err));
return data;
}