Skip to content

Commit 5b733ef

Browse files
committed
Enhances #694 - Add notification for inaccessible documents
1 parent d14f318 commit 5b733ef

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/components/Documents/DocumentTable.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Box from '@mui/material/Box';
99
import { useMediaQuery } from '@mui/material';
1010
// Context Imports
1111
import { DocumentListContext } from '@contexts';
12-
import { useSession } from '@hooks';
12+
import { useNotification, useSession } from '@hooks';
1313
// Utility Imports
1414
import { getBlobFromSolid } from '@utils';
1515
// Theme Imports
@@ -35,6 +35,7 @@ import DocumentsDesktop from './DocumentsDesktop';
3535
const DocumentTable = ({ handleAclPermissionsModal, handleSelectDeleteDoc }) => {
3636
const { session } = useSession();
3737
const { documentListObject, loadingDocuments } = useContext(DocumentListContext);
38+
const { addNotification } = useNotification();
3839

3940
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
4041
const isSmallScreenHeight = useMediaQuery('(max-height: 600px)');
@@ -59,10 +60,21 @@ const DocumentTable = ({ handleAclPermissionsModal, handleSelectDeleteDoc }) =>
5960
* @returns {Promise<Blob>} A promise that resolves with the Blob of the document.
6061
* @throws {Error} Throws an error if there is an issue fetching the document blob.
6162
*/
62-
const urlFileBlob = await getBlobFromSolid(session, urlToOpen);
63+
try {
64+
const urlFileBlob = await getBlobFromSolid(session, urlToOpen);
6365

64-
// Open a new window to display the document using the blob URL
65-
window.open(urlFileBlob);
66+
// Open a new window to display the document using the blob URL
67+
window.open(urlFileBlob);
68+
} catch (e) {
69+
if (e?.statusCode === 403) {
70+
addNotification('error', 'You do not have permission to view this document');
71+
} else {
72+
addNotification(
73+
'error',
74+
`Document preview failed. Reason: ${e?.message || 'Unknown error'}`
75+
);
76+
}
77+
}
6678
};
6779

6880
// Maps raw document types to user-friendly display names using `DOC_TYPES`

0 commit comments

Comments
 (0)