updated corss-search export error handling

This commit is contained in:
juhanikat
2025-07-14 14:39:59 +03:00
parent d7ec0f6bcc
commit 552cd9b91c
+10 -1
View File
@@ -124,10 +124,13 @@ router.get(`/export/:columnfilters/:sorting`, async (req, res) => {
return res.status(403).send('Unknown error')
}
res.attachment(`cross_search${currentDateAsString()}.csv`) // filename will get overwritten in frontend when fetching data from this route
res.on('finish', () => {
logger.info('Cross search export sent.')
})
res.on('error', () => {
logger.info('ERROR!')
})
res.attachment(`cross_search${currentDateAsString()}.csv`) // filename will get overwritten in frontend when fetching data from this route
// quoteColumns is needed to make sure linebreaks do not mess up the data
const stream = format({ headers: true, quoteColumns: true }).transform(
@@ -142,6 +145,7 @@ router.get(`/export/:columnfilters/:sorting`, async (req, res) => {
}
})
try {
for (const data of dataArray) {
if (data) {
for (const row of data) {
@@ -152,6 +156,11 @@ router.get(`/export/:columnfilters/:sorting`, async (req, res) => {
}
}
}
} catch (error) {
logger.error(
'Error in crosssearch/export: Could not write to stream, user might have left the page or refreshed it.'
)
}
return stream.end()
})