Skip to content

Commit 4a79926

Browse files
feat: add Sentry error capture to page title and image plugin (#82) (#89)
Co-authored-by: Ona <no-reply@ona.com>
1 parent fd94bf9 commit 4a79926

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

src/components/editor/image-plugin.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
DROP_COMMAND,
1313
type LexicalCommand,
1414
} from "lexical";
15+
import * as Sentry from "@sentry/nextjs";
1516
import { $createImageNode, type ImagePayload } from "@/components/editor/image-node";
1617
import { createClient } from "@/lib/supabase/client";
1718
import { captureSupabaseError } from "@/lib/sentry";
@@ -96,14 +97,18 @@ export function ImagePlugin(): null {
9697
event.preventDefault();
9798

9899
for (const file of imageFiles) {
99-
void uploadImage(file).then((url) => {
100-
if (url) {
101-
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
102-
src: url,
103-
altText: file.name,
104-
});
105-
}
106-
});
100+
void uploadImage(file)
101+
.then((url) => {
102+
if (url) {
103+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
104+
src: url,
105+
altText: file.name,
106+
});
107+
}
108+
})
109+
.catch((error) => {
110+
Sentry.captureException(error);
111+
});
107112
}
108113

109114
return true;
@@ -140,12 +145,16 @@ export function openImagePicker(editor: ReturnType<typeof useLexicalComposerCont
140145
const file = input.files?.[0];
141146
if (!file) return;
142147

143-
const url = await uploadImage(file);
144-
if (url) {
145-
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
146-
src: url,
147-
altText: file.name,
148-
});
148+
try {
149+
const url = await uploadImage(file);
150+
if (url) {
151+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
152+
src: url,
153+
altText: file.name,
154+
});
155+
}
156+
} catch (error) {
157+
Sentry.captureException(error);
149158
}
150159
};
151160
input.click();

src/components/page-title.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useCallback, useEffect, useRef, useState } from "react";
44
import { createClient } from "@/lib/supabase/client";
5+
import { captureSupabaseError } from "@/lib/sentry";
56

67
interface PageTitleProps {
78
pageId: string;
@@ -37,6 +38,8 @@ export function PageTitle({ pageId, initialTitle }: PageTitleProps) {
3738

3839
if (!error) {
3940
lastSavedRef.current = trimmed;
41+
} else {
42+
captureSupabaseError(error, "page.title.save");
4043
}
4144
},
4245
[pageId]

0 commit comments

Comments
 (0)