Skip to content

Commit 9dbd85f

Browse files
authored
create sendErrorEmail component, don't send if encrypted/offline (#302)
* create sendErrorEmail component, don't send if encrypted/offline * type safe error
1 parent efa7a82 commit 9dbd85f

4 files changed

Lines changed: 63 additions & 77 deletions

File tree

src/components/Export.tsx

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import localStorageSet from "roamjs-components/util/localStorageSet";
5050
import isLiveBlock from "roamjs-components/queries/isLiveBlock";
5151
import createPage from "roamjs-components/writes/createPage";
5252
import { createInitialTldrawProps } from "../utils/createInitialTldrawProps";
53+
import sendErrorEmail from "../utils/sendErrorEmail";
5354

5455
const ExportProgress = ({ id }: { id: string }) => {
5556
const [progress, setProgress] = useState(0);
@@ -447,26 +448,14 @@ const ExportDialog: ExportDialogComponent = ({
447448
} catch (e) {
448449
const error = e as Error;
449450
renderToast({
450-
content: "Looks like there was an error. The team has been notified.",
451+
content: "Looks like there was an error.",
451452
intent: "danger",
452453
id: "query-builder-error",
453454
});
454-
apiPost({
455-
domain: "https://api.samepage.network",
456-
path: "errors",
457-
data: {
458-
method: "extension-error",
459-
type: "Query Builder Export Dialog Failed",
460-
message: error.message,
461-
stack: error.stack,
462-
version: process.env.VERSION,
463-
notebookUuid: JSON.stringify({
464-
owner: "RoamJS",
465-
app: "query-builder",
466-
workspace: window.roamAlphaAPI.graph.name,
467-
}),
468-
},
469-
}).catch(() => {});
455+
sendErrorEmail({
456+
error,
457+
type: "Query Builder Export Dialog Failed",
458+
});
470459
} finally {
471460
setLoading(false);
472461
onClose();
@@ -719,28 +708,16 @@ const ExportDialog: ExportDialogComponent = ({
719708
}
720709
} catch (e) {
721710
const error = e as Error;
722-
apiPost({
723-
domain: "https://api.samepage.network",
724-
path: "errors",
711+
sendErrorEmail({
712+
type: "Query Builder Export Dialog Failed",
713+
error,
725714
data: {
726-
method: "extension-error",
727-
type: "Query Builder Export Dialog Failed",
728-
data: {
729-
activeExportType,
730-
filename,
731-
results:
732-
typeof results === "function" ? "dynamic" : results,
733-
},
734-
message: error.message,
735-
stack: error.stack,
736-
version: process.env.VERSION,
737-
notebookUuid: JSON.stringify({
738-
owner: "RoamJS",
739-
app: "query-builder",
740-
workspace: window.roamAlphaAPI.graph.name,
741-
}),
715+
activeExportType,
716+
filename,
717+
results:
718+
typeof results === "function" ? "dynamic" : results,
742719
},
743-
}).catch(() => {});
720+
});
744721
setDialogOpen(true);
745722
setError((e as Error).message);
746723
} finally {

src/components/tldraw/Tldraw.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
DiscourseRelationUtil,
6161
} from "./DiscourseRelationsUtil";
6262
import { isPageUid } from "../../utils/isPageUid";
63-
import apiPost from "roamjs-components/util/apiPost";
63+
import sendErrorEmail from "../../utils/sendErrorEmail";
6464

6565
declare global {
6666
interface Window {
@@ -794,27 +794,13 @@ const TldrawCanvas = ({ title }: Props) => {
794794
const handleTldrawError = (
795795
e: CustomEvent<{ message: string; stack: string | null }>
796796
) => {
797-
apiPost({
798-
domain: "https://api.samepage.network",
799-
path: "errors",
797+
sendErrorEmail({
798+
type: "Tldraw Error",
799+
error: new Error(e.detail.message, { cause: e.detail.stack }),
800800
data: {
801-
method: "extension-error",
802-
type: "Tldraw Error",
803-
message: e.detail.message,
804-
stack: e.detail.stack,
805-
version: process.env.VERSION,
806-
notebookUuid: JSON.stringify({
807-
owner: "RoamJS",
808-
app: "query-builder",
809-
workspace: window.roamAlphaAPI.graph.name,
810-
}),
811-
data: {
812-
title,
813-
},
801+
title,
814802
},
815-
}).catch(() => {});
816-
817-
console.error("Tldraw Error:", e.detail);
803+
});
818804
};
819805

820806
document.addEventListener(

src/utils/calcCanvasNodeSizeAndImg.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import getDiscourseNodes from "./getDiscourseNodes";
88
import resolveRefs from "roamjs-components/dom/resolveRefs";
99
import { render as renderToast } from "roamjs-components/components/Toast";
1010
import { loadImage } from "./loadImage";
11-
import apiPost from "roamjs-components/util/apiPost";
11+
import sendErrorEmail from "./sendErrorEmail";
1212

1313
const extractFirstImageUrl = (text: string): string | null => {
1414
const regex = /!\[.*?\]\((https:\/\/[^)]+)\)/;
@@ -99,27 +99,15 @@ const calcCanvasNodeSizeAndImg = async ({
9999
};
100100
} catch (e) {
101101
const error = e as Error;
102-
apiPost({
103-
domain: "https://api.samepage.network",
104-
path: "errors",
102+
sendErrorEmail({
103+
type: "Canvas Image Load Failed",
104+
error,
105105
data: {
106-
method: "extension-error",
107-
type: "Canvas Image Load Failed",
108-
message: error.message,
109-
stack: error.stack,
110-
version: process.env.VERSION,
111-
notebookUuid: JSON.stringify({
112-
owner: "RoamJS",
113-
app: "query-builder",
114-
workspace: window.roamAlphaAPI.graph.name,
115-
}),
116-
data: {
117-
uid,
118-
nodeText,
119-
imageUrl,
120-
},
106+
uid,
107+
nodeText,
108+
imageUrl,
121109
},
122-
}).catch(() => {});
110+
});
123111
renderToast({
124112
id: "tldraw-image-load-fail",
125113
content: error.message,

src/utils/sendErrorEmail.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import apiPost from "roamjs-components/util/apiPost";
2+
3+
const sendErrorEmail = ({
4+
error,
5+
data,
6+
type,
7+
}: {
8+
error: Error;
9+
data?: Record<string, unknown>;
10+
type: string;
11+
}) => {
12+
const isEncrypted = window.roamAlphaAPI.graph.isEncrypted;
13+
const isOffline = window.roamAlphaAPI.graph.type === "offline";
14+
if (isEncrypted || isOffline) return;
15+
16+
apiPost({
17+
domain: "https://api.samepage.network",
18+
path: "errors",
19+
data: {
20+
method: "extension-error",
21+
type,
22+
message: error.message,
23+
stack: error.stack,
24+
version: process.env.VERSION,
25+
notebookUuid: JSON.stringify({
26+
owner: "RoamJS",
27+
app: "query-builder",
28+
workspace: window.roamAlphaAPI.graph.name,
29+
}),
30+
data,
31+
},
32+
}).catch(() => {});
33+
};
34+
35+
export default sendErrorEmail;

0 commit comments

Comments
 (0)