Add ended logic

This commit is contained in:
cgonzalez 2021-03-24 10:55:45 +00:00
parent acff0c0413
commit 8c35f8912c

View File

@ -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)');