Skip to content

Commit

Permalink
Fixed bug in UniversalBot.send()
Browse files Browse the repository at this point in the history
- Didn't protect against empty list of messages,
- Also wasn't returning errors in an edge case.
  • Loading branch information
Stevenic committed Mar 21, 2017
1 parent b74bcb9 commit 2a78d18
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Node/core/lib/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,14 +557,17 @@ 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);
}
cb(err);
});
}
else {
cb(null);
}
};
Session.prototype.onFinishBatch = function (cb) {
var _this = this;
Expand Down
4 changes: 2 additions & 2 deletions Node/core/lib/bots/UniversalBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -213,7 +213,7 @@ var UniversalBot = (function (_super) {
}, _this.errorLogger(done));
}
else if (done) {
done(null);
done(err);
}
}));
};
Expand Down
4 changes: 3 additions & 1 deletion Node/core/src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Node/core/src/bots/UniversalBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}));
}
Expand Down

0 comments on commit 2a78d18

Please sign in to comment.