Destroy file-download stream on error

This commit is contained in:
Simon Detheridge 2020-03-30 17:13:40 +01:00
parent 4cb4d450be
commit 87b8f8e194

View file

@ -61,15 +61,18 @@ function getFile(req, res, next) {
}
pipeline(fileStream, res, err => {
if (err && err.code === 'ERR_STREAM_PREMATURE_CLOSE') {
res.end()
} else if (err) {
next(
new Errors.ReadError({
message: 'error transferring stream',
info: { bucket, key, format, style }
}).withCause(err)
)
if (err) {
fileStream.destroy()
if (err.code === 'ERR_STREAM_PREMATURE_CLOSE') {
res.end()
} else {
next(
new Errors.ReadError({
message: 'error transferring stream',
info: { bucket, key, format, style }
}).withCause(err)
)
}
}
})
})