Add ended logic

remotes/origin/feature/ch139802/phl-inconsistent-errors-when-downloading
cgonzalez 4 years ago
parent acff0c0413
commit 8c35f8912c

@ -325,6 +325,7 @@ function ExportRequest (ostream, callback, beforeSink) {
this.ostream = ostream;
this.istream = null;
this.canceled = false;
this.ended = false;
var that = this;
logger.info({ custom: true }, 'New export request');
@ -373,17 +374,22 @@ ExportRequest.prototype.sendFile = function (err, filename, callback) {
.on('error', function (e) {
logger.info({ custom: true }, 'Sending file: on error');
console.log("Can't send response: " + e);
that.ended = true;
that.ostream.end();
that.cb(e);
callback();
})
.on('end', () => {
logger.info({ custom: true }, 'Sending file: on end');
that.ended = true;
that.cb();
callback();
})
.on('close', function() {
logger.info({ custom: true }, 'Sending file: testing on close event');
if (!that.ended) {
callback();
}
});
} else {
logger.info({ custom: true }, 'It was cancelled (sending file)');

Loading…
Cancel
Save