Skip to content

Commit c8e0c4a

Browse files
committed
more lenient error if posthog is missing
1 parent 022e845 commit c8e0c4a

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

apps/website/app/utils/internalErrorSsr.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { PostHog } from "posthog-node";
22

33
let posthog: PostHog | undefined;
44

5-
const getPostHog = (): PostHog => {
5+
const getPostHog = (): PostHog | undefined => {
66
if (posthog === undefined) {
77
if (
88
!process.env.NEXT_PUBLIC_POSTHOG_KEY ||
99
!process.env.NEXT_PUBLIC_POSTHOG_HOST
1010
) {
11-
throw new Error("PostHog environment variables are not set");
11+
console.error("PostHog environment variables are not set");
12+
return;
1213
}
1314
posthog = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
1415
host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
@@ -52,11 +53,11 @@ export const internalError = ({
5253
}
5354
}
5455
const posthog = getPostHog();
55-
const result = posthog.captureException(error, undefined, {
56-
...context,
57-
type: slugType,
58-
});
59-
console.error(result);
56+
if (posthog)
57+
posthog.captureException(error, undefined, {
58+
...context,
59+
type: slugType,
60+
});
6061
if (process.env.NODE_ENV === "development") console.error(error);
6162
}
6263
};

0 commit comments

Comments
 (0)