mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Added try catch to redis methods.
This commit is contained in:
parent
aaa51e72d3
commit
0e4f4affea
1 changed files with 28 additions and 17 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { serializeError } from 'serialize-error';
|
||||
import { getWebsiteSession, getWebsite } from 'queries';
|
||||
import { Website, Session } from '@prisma/client';
|
||||
import { getClient, redisEnabled } from '@umami/redis-client';
|
||||
|
|
@ -5,16 +6,21 @@ import { getClient, redisEnabled } from '@umami/redis-client';
|
|||
export async function fetchWebsite(websiteId: string): Promise<Website> {
|
||||
let website = null;
|
||||
|
||||
if (redisEnabled) {
|
||||
const redis = getClient();
|
||||
try {
|
||||
if (redisEnabled) {
|
||||
const redis = getClient();
|
||||
|
||||
website = await redis.fetch(`website:${websiteId}`, () => getWebsite(websiteId), 86400);
|
||||
} else {
|
||||
website = await getWebsite(websiteId);
|
||||
}
|
||||
website = await redis.fetch(`website:${websiteId}`, () => getWebsite(websiteId), 86400);
|
||||
} else {
|
||||
website = await getWebsite(websiteId);
|
||||
}
|
||||
|
||||
if (!website || website.deletedAt) {
|
||||
return null;
|
||||
if (!website || website.deletedAt) {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('FETCH WEBSITE ERROR:', serializeError(e));
|
||||
}
|
||||
|
||||
return website;
|
||||
|
|
@ -23,16 +29,21 @@ export async function fetchWebsite(websiteId: string): Promise<Website> {
|
|||
export async function fetchSession(websiteId: string, sessionId: string): Promise<Session> {
|
||||
let session = null;
|
||||
|
||||
if (redisEnabled) {
|
||||
const redis = getClient();
|
||||
try {
|
||||
if (redisEnabled) {
|
||||
const redis = getClient();
|
||||
|
||||
session = await redis.fetch(
|
||||
`session:${sessionId}`,
|
||||
() => getWebsiteSession(websiteId, sessionId),
|
||||
86400,
|
||||
);
|
||||
} else {
|
||||
session = await getWebsiteSession(websiteId, sessionId);
|
||||
session = await redis.fetch(
|
||||
`session:${sessionId}`,
|
||||
() => getWebsiteSession(websiteId, sessionId),
|
||||
86400,
|
||||
);
|
||||
} else {
|
||||
session = await getWebsiteSession(websiteId, sessionId);
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('FETCH SESSION ERROR:', serializeError(e));
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue