From 2a78d18f3813a151effffa25a8c0c5fd892edd80 Mon Sep 17 00:00:00 2001 From: Steve Ickman Date: Mon, 13 Mar 2017 15:52:43 -0700 Subject: [PATCH] Fixed bug in UniversalBot.send() - Didn't protect against empty list of messages, - Also wasn't returning errors in an edge case. --- Node/core/lib/Session.js | 5 ++++- Node/core/lib/bots/UniversalBot.js | 4 ++-- Node/core/src/Session.ts | 4 +++- Node/core/src/bots/UniversalBot.ts | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Node/core/lib/Session.js b/Node/core/lib/Session.js index e80fbb7096..c7a7c03196 100644 --- a/Node/core/lib/Session.js +++ b/Node/core/lib/Session.js @@ -557,7 +557,7 @@ var Session = (function (_super) { }; Session.prototype.onSend = function (batch, cb) { var _this = this; - if (batch) { + if (batch && batch.length > 0) { this.options.onSend(batch, function (err) { if (err) { _this.logger.error(_this.dialogStack(), err); @@ -565,6 +565,9 @@ var Session = (function (_super) { cb(err); }); } + else { + cb(null); + } }; Session.prototype.onFinishBatch = function (cb) { var _this = this; diff --git a/Node/core/lib/bots/UniversalBot.js b/Node/core/lib/bots/UniversalBot.js index ba3ce2bb87..8fdece72db 100644 --- a/Node/core/lib/bots/UniversalBot.js +++ b/Node/core/lib/bots/UniversalBot.js @@ -202,7 +202,7 @@ var UniversalBot = (function (_super) { }, cb); }, cb); }, this.errorLogger(function (err) { - if (!err) { + if (!err && list.length > 0) { _this.tryCatch(function () { var channelId = list[0].address.channelId; var connector = _this.connector(channelId); @@ -213,7 +213,7 @@ var UniversalBot = (function (_super) { }, _this.errorLogger(done)); } else if (done) { - done(null); + done(err); } })); }; diff --git a/Node/core/src/Session.ts b/Node/core/src/Session.ts index 4c15ff3445..7816b1f6b4 100644 --- a/Node/core/src/Session.ts +++ b/Node/core/src/Session.ts @@ -687,13 +687,15 @@ export class Session extends events.EventEmitter { } private onSend(batch: IMessage[], cb: (err: Error) => void): void { - if (batch) { + if (batch && batch.length > 0) { this.options.onSend(batch, (err) => { if (err) { this.logger.error(this.dialogStack(), err); } cb(err); }) + } else { + cb(null); } } diff --git a/Node/core/src/bots/UniversalBot.ts b/Node/core/src/bots/UniversalBot.ts index e91f3ff0bc..a886870bd7 100644 --- a/Node/core/src/bots/UniversalBot.ts +++ b/Node/core/src/bots/UniversalBot.ts @@ -292,7 +292,7 @@ export class UniversalBot extends Library { }, cb); }, cb); }, this.errorLogger((err) => { - if (!err) { + if (!err && list.length > 0) { this.tryCatch(() => { // All messages should be targeted at the same channel. var channelId = list[0].address.channelId; @@ -303,7 +303,7 @@ export class UniversalBot extends Library { connector.send(list, this.errorLogger(done)); }, this.errorLogger(done)); } else if (done) { - done(null); + done(err); } })); }