From dc5158257e7d21469b99b8a6b1136b85efc51aa0 Mon Sep 17 00:00:00 2001 From: Ajay Date: Fri, 13 Sep 2024 14:36:52 -0400 Subject: [PATCH] Fix errors when postgres returns undefined and trying to save to redis --- src/utils/queryCacher.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/queryCacher.ts b/src/utils/queryCacher.ts index 69dff0d..e8ccaa2 100644 --- a/src/utils/queryCacher.ts +++ b/src/utils/queryCacher.ts @@ -21,7 +21,8 @@ async function get(fetchFromDB: () => Promise, key: string): Promise { 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; }