diff --git a/apps/backend/src/middlewares/factory/zip.ts b/apps/backend/src/middlewares/factory/zip.ts index 9fbe256dd0..4c85449d06 100644 --- a/apps/backend/src/middlewares/factory/zip.ts +++ b/apps/backend/src/middlewares/factory/zip.ts @@ -51,6 +51,12 @@ router.get(`/${ZIPType.ATTACHMENT}/:proposal_pks`, async (req, res, next) => { if (!data) { throw new Error('Could not get attachments'); } + + const attachments = data.flatMap(({ attachments }) => attachments); + if (attachments.length === 0) { + return res.status(404).send('NO_ATTACHMENTS'); + } + downloadService.callFactoryService( DownloadType.ZIP, ZIPType.ATTACHMENT, diff --git a/apps/e2e/cypress/e2e/proposalAdministration.cy.ts b/apps/e2e/cypress/e2e/proposalAdministration.cy.ts index be6ad14021..50daad7746 100644 --- a/apps/e2e/cypress/e2e/proposalAdministration.cy.ts +++ b/apps/e2e/cypress/e2e/proposalAdministration.cy.ts @@ -443,6 +443,9 @@ context('Proposal administration tests', () => { 'attachment' ); + cy.get('[role="alert"]').should('exist'); + cy.get('[role="alert"]').contains('No attachments found'); + cy.contains(proposalFixedName) .parent() .find('input[type="checkbox"]') @@ -463,6 +466,9 @@ context('Proposal administration tests', () => { cy.get('[data-cy="preparing-download-dialog-item"]').contains( '2 selected items' ); + + cy.get('[role="alert"]').should('exist'); + cy.get('[role="alert"]').contains('No attachments found'); }); it('Downloaded proposal filename format is RB_SURNAME_YYYY', function () { diff --git a/apps/frontend/src/context/DownloadContextProvider.tsx b/apps/frontend/src/context/DownloadContextProvider.tsx index f776d68824..f80648a368 100644 --- a/apps/frontend/src/context/DownloadContextProvider.tsx +++ b/apps/frontend/src/context/DownloadContextProvider.tsx @@ -252,7 +252,12 @@ export const DownloadContextProvider = ({ await promptDownload(response); }) .catch((error) => { - if (error !== 'EXTERNAL_TOKEN_INVALID' && error.name !== 'AbortError') { + if (error === 'NO_ATTACHMENTS') { + enqueueSnackbar('No attachments found', { variant: 'info' }); + } else if ( + error !== 'EXTERNAL_TOKEN_INVALID' && + error.name !== 'AbortError' + ) { enqueueSnackbar('Failed to download file', { variant: 'error' }); } })