Skip to content

Commit 48ce65c

Browse files
committed
missing file
1 parent 1ee27f6 commit 48ce65c

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use client";
2+
3+
import type { Properties } from "posthog-js";
4+
import { usePostHog } from "posthog-js/react";
5+
6+
const NON_WORD = /\W+/g;
7+
8+
const internalError = ({
9+
error,
10+
type,
11+
context,
12+
forceSendInDev = false,
13+
}: {
14+
error: unknown;
15+
type?: string;
16+
context?: Properties;
17+
forceSendInDev?: boolean;
18+
}): void => {
19+
if (process.env.NODE_ENV === "development" && forceSendInDev !== true) {
20+
console.error(error);
21+
} else {
22+
const posthog = usePostHog();
23+
type = type || "Internal Error";
24+
const slugType = type.replaceAll(NON_WORD, "-").toLowerCase();
25+
context = {
26+
type,
27+
...(context || {}),
28+
};
29+
30+
if (typeof error === "string") {
31+
error = new Error(error);
32+
} else if (!(error instanceof Error)) {
33+
try {
34+
const serialized = JSON.stringify(error);
35+
error = new Error(serialized);
36+
} catch {
37+
error = new Error(typeof error);
38+
}
39+
}
40+
posthog.captureException(error, { ...context, type: slugType });
41+
}
42+
};
43+
44+
export default internalError;

0 commit comments

Comments
 (0)