Added try catch to redis methods.

This commit is contained in:
Mike Cao 2025-01-18 02:11:06 -08:00
parent aaa51e72d3
commit 0e4f4affea

View file

@ -1,3 +1,4 @@
import { serializeError } from 'serialize-error';
import { getWebsiteSession, getWebsite } from 'queries'; import { getWebsiteSession, getWebsite } from 'queries';
import { Website, Session } from '@prisma/client'; import { Website, Session } from '@prisma/client';
import { getClient, redisEnabled } from '@umami/redis-client'; import { getClient, redisEnabled } from '@umami/redis-client';
@ -5,6 +6,7 @@ import { getClient, redisEnabled } from '@umami/redis-client';
export async function fetchWebsite(websiteId: string): Promise<Website> { export async function fetchWebsite(websiteId: string): Promise<Website> {
let website = null; let website = null;
try {
if (redisEnabled) { if (redisEnabled) {
const redis = getClient(); const redis = getClient();
@ -16,6 +18,10 @@ export async function fetchWebsite(websiteId: string): Promise<Website> {
if (!website || website.deletedAt) { if (!website || website.deletedAt) {
return null; return null;
} }
} catch (e) {
// eslint-disable-next-line no-console
console.log('FETCH WEBSITE ERROR:', serializeError(e));
}
return website; return website;
} }
@ -23,6 +29,7 @@ export async function fetchWebsite(websiteId: string): Promise<Website> {
export async function fetchSession(websiteId: string, sessionId: string): Promise<Session> { export async function fetchSession(websiteId: string, sessionId: string): Promise<Session> {
let session = null; let session = null;
try {
if (redisEnabled) { if (redisEnabled) {
const redis = getClient(); const redis = getClient();
@ -34,6 +41,10 @@ export async function fetchSession(websiteId: string, sessionId: string): Promis
} else { } else {
session = await getWebsiteSession(websiteId, sessionId); session = await getWebsiteSession(websiteId, sessionId);
} }
} catch (e) {
// eslint-disable-next-line no-console
console.log('FETCH SESSION ERROR:', serializeError(e));
}
if (!session) { if (!session) {
return null; return null;