Skip to content

Commit f9ff578

Browse files
committed
🥅(frontend) improve error handling during upload
Catch and log errors when replacing blocks during file upload.
1 parent 1372438 commit f9ff578

File tree

2 files changed

+55
-40
lines changed

2 files changed

+55
-40
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/UploadLoaderBlock.tsx

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,43 @@ const UploadLoaderBlockComponent = ({
7070
loopCheckDocMediaStatus(url)
7171
.then((response) => {
7272
// Replace the loading block with the resource block (image, audio, video, pdf ...)
73-
editor.replaceBlocks(
74-
[block.id],
75-
[
76-
{
77-
type: block.props.blockUploadType,
78-
props: {
79-
url: `${mediaUrl}${response.file}`,
80-
showPreview: block.props.blockUploadShowPreview,
81-
name: block.props.blockUploadName,
82-
caption: '',
83-
backgroundColor: 'default',
84-
textAlignment: 'left',
85-
},
86-
} as never,
87-
],
88-
);
73+
try {
74+
editor.replaceBlocks(
75+
[block.id],
76+
[
77+
{
78+
type: block.props.blockUploadType,
79+
props: {
80+
url: `${mediaUrl}${response.file}`,
81+
showPreview: block.props.blockUploadShowPreview,
82+
name: block.props.blockUploadName,
83+
caption: '',
84+
backgroundColor: 'default',
85+
textAlignment: 'left',
86+
},
87+
} as never,
88+
],
89+
);
90+
} catch {
91+
/* During collaboration, another user might have updated the block */
92+
}
8993
})
9094
.catch((error) => {
9195
console.error('Error analyzing file:', error);
9296

93-
editor.updateBlock(block.id, {
94-
type: 'uploadLoader',
95-
props: {
96-
type: 'warning',
97-
information: t(
98-
'The antivirus has detected an anomaly in your file.',
99-
),
100-
},
101-
});
97+
try {
98+
editor.updateBlock(block.id, {
99+
type: 'uploadLoader',
100+
props: {
101+
type: 'warning',
102+
information: t(
103+
'The antivirus has detected an anomaly in your file.',
104+
),
105+
},
106+
});
107+
} catch {
108+
/* During collaboration, another user might have updated the block */
109+
}
102110
});
103111
}, [block, editor, mediaUrl]);
104112

src/frontend/apps/impress/src/features/docs/doc-editor/hook/useUploadFile.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { captureException } from '@sentry/nextjs';
12
import { useCallback, useEffect } from 'react';
23
import { useTranslation } from 'react-i18next';
34

@@ -70,22 +71,28 @@ export const useUploadStatus = (editor: DocsBlockNoteEditor) => {
7071
const timeoutId = setTimeout(() => {
7172
// Replace the resource block by a uploadLoader block
7273
// to show analyzing status
73-
editor.replaceBlocks(
74-
[blockChanges.block.id],
75-
[
76-
{
77-
type: 'uploadLoader',
78-
props: {
79-
information: t('Analyzing file...'),
80-
type: 'loading',
81-
blockUploadName,
82-
blockUploadType,
83-
blockUploadUrl,
84-
blockUploadShowPreview,
74+
try {
75+
editor.replaceBlocks(
76+
[blockChanges.block.id],
77+
[
78+
{
79+
type: 'uploadLoader',
80+
props: {
81+
information: t('Analyzing file...'),
82+
type: 'loading',
83+
blockUploadName,
84+
blockUploadType,
85+
blockUploadUrl,
86+
blockUploadShowPreview,
87+
},
8588
},
86-
},
87-
],
88-
);
89+
],
90+
);
91+
} catch (error) {
92+
captureException(error, {
93+
extra: { info: 'Error replacing block for upload loader' },
94+
});
95+
}
8996
}, 250);
9097

9198
return () => {

0 commit comments

Comments
 (0)