🥅(frontend) improve error handling during upload
Catch and log errors when replacing blocks during file upload.
This commit is contained in:
@@ -70,6 +70,7 @@ const UploadLoaderBlockComponent = ({
|
|||||||
loopCheckDocMediaStatus(url)
|
loopCheckDocMediaStatus(url)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
// Replace the loading block with the resource block (image, audio, video, pdf ...)
|
// Replace the loading block with the resource block (image, audio, video, pdf ...)
|
||||||
|
try {
|
||||||
editor.replaceBlocks(
|
editor.replaceBlocks(
|
||||||
[block.id],
|
[block.id],
|
||||||
[
|
[
|
||||||
@@ -86,10 +87,14 @@ const UploadLoaderBlockComponent = ({
|
|||||||
} as never,
|
} as never,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
} catch {
|
||||||
|
/* During collaboration, another user might have updated the block */
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error analyzing file:', error);
|
console.error('Error analyzing file:', error);
|
||||||
|
|
||||||
|
try {
|
||||||
editor.updateBlock(block.id, {
|
editor.updateBlock(block.id, {
|
||||||
type: 'uploadLoader',
|
type: 'uploadLoader',
|
||||||
props: {
|
props: {
|
||||||
@@ -99,6 +104,9 @@ const UploadLoaderBlockComponent = ({
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} catch {
|
||||||
|
/* During collaboration, another user might have updated the block */
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, [block, editor, mediaUrl]);
|
}, [block, editor, mediaUrl]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { captureException } from '@sentry/nextjs';
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
@@ -70,6 +71,7 @@ export const useUploadStatus = (editor: DocsBlockNoteEditor) => {
|
|||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
// Replace the resource block by a uploadLoader block
|
// Replace the resource block by a uploadLoader block
|
||||||
// to show analyzing status
|
// to show analyzing status
|
||||||
|
try {
|
||||||
editor.replaceBlocks(
|
editor.replaceBlocks(
|
||||||
[blockChanges.block.id],
|
[blockChanges.block.id],
|
||||||
[
|
[
|
||||||
@@ -86,6 +88,11 @@ export const useUploadStatus = (editor: DocsBlockNoteEditor) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
} catch (error) {
|
||||||
|
captureException(error, {
|
||||||
|
extra: { info: 'Error replacing block for upload loader' },
|
||||||
|
});
|
||||||
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user