Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions src/http/DataQueryEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,35 @@ const onRow = (res, unicastMessage, delimiter, format = 'object', version, metri
}

const streamData = (res, stream, format, version, metrics) => {
let delimiter = ''
stream.on('data', (row) => {
// first row
if (delimiter === '') {
onStarted(res)
}
onRow(res, row, delimiter, format, version, metrics)
delimiter = ','
})
stream.on('end', () => {
if (delimiter === '') {
onStarted(res)
}
res.write(']')
res.end()
})
stream.on('error', (err) => {
try {
let delimiter = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If stream.on is failing, it seems like a fundamental problem with the code that should cause a crash instead of being wrapped in a 500 error code and sent back to client? I.e. it is an unexpected error that should not really ever occur unless there is a problem with our code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's true

stream.on('data', (row) => {
// first row
if (delimiter === '') {
onStarted(res)
}
onRow(res, row, delimiter, format, version, metrics)
delimiter = ','
})
stream.on('end', () => {
if (delimiter === '') {
onStarted(res)
}
res.write(']')
res.end()
})
stream.on('error', (err) => {
logger.error(err)
res.status(500).send({
error: 'Failed to fetch data!'
})
})
} catch (err) {
logger.error(err)
res.status(500).send({
error: 'Failed to fetch data!'
})
})
}
}

function parseIntIfExists(x) {
Expand Down
Loading