Skip to content

Commit abc3b18

Browse files
committed
also sendMail along with posthog
1 parent 434e799 commit abc3b18

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

apps/roam/src/utils/internalError.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@ import type { Properties } from "posthog-js";
33
import renderToast from "roamjs-components/components/Toast";
44
import { getVersionWithDate } from "~/utils/getVersion";
55
import getCurrentUserDisplayName from "roamjs-components/queries/getCurrentUserDisplayName";
6+
import sendErrorEmail from "~/utils/sendErrorEmail";
67

78
const internalError = ({
89
error,
910
userMessage,
1011
type,
1112
context,
13+
sendEmail, // true by default
1214
}: {
1315
error: unknown;
1416
type?: string;
1517
userMessage?: string;
1618
context?: Properties;
19+
sendEmail?: boolean;
1720
}): void => {
1821
if (process.env.NODE_ENV === "development") {
1922
console.error(error, context);
2023
} else {
2124
const { version, buildDate } = getVersionWithDate();
2225
const username = getCurrentUserDisplayName();
2326
if (username) posthog.identify(username);
27+
type = type || "internal-error";
2428
context = {
2529
app: "Roam",
26-
type: type || "internal-error",
30+
type,
2731
graphName: window.roamAlphaAPI?.graph?.name || "unknown",
2832
version: version || "-",
2933
buildDate: buildDate || "-",
@@ -41,6 +45,16 @@ const internalError = ({
4145
}
4246
}
4347
posthog.captureException(error, context);
48+
if (sendEmail !== false) {
49+
sendErrorEmail({
50+
// by now error is an Error but TS did not figure it out
51+
error: error as Error,
52+
type,
53+
context,
54+
}).catch(() => {
55+
console.error("Could not send error email", error, type, context);
56+
});
57+
}
4458
}
4559
if (userMessage !== undefined) {
4660
renderToast({

0 commit comments

Comments
 (0)