Skip to content

Commit

Permalink
Merge pull request #264 from raphiz/fix-uncaught-bosh-error-on-timeout
Browse files Browse the repository at this point in the history
Fix Uncaught error on timeout (bosh)
  • Loading branch information
legastero committed May 17, 2018
2 parents 8558ffb + f20c6e7 commit c1ba5e0
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions lib/transports/bosh.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,36 +244,33 @@ BOSHConnection.prototype.request = function (bosh) {
method: 'POST',
strictSSL: true,
headers: {
'Content-Type': 'text/xml'
'Content-Type': 'text/xml'
}
}, self.config.wait * 1.5, this.config.maxRetries).catch(function (err) {
self.hasStream = false;
var serr = new self.stanzas.StreamError({
condition: 'connection-timeout'
},self.config.wait * 1.5, this.config.maxRetries
).then(function (body) {
self.emit('raw:incoming', new Buffer(body, 'utf8').toString());
}).then(function () {
self.requests = filter(self.requests, function (item) {
return item.id !== ticket.id;
});
// do not (re)start long polling if terminating, or request is pending, or before authentication
if (bosh.type !== 'terminate' && !self.requests.length && self.authenticated) {
// Delay next auto-request by two ticks since we're likely
// to send data anyway next tick.
process.nextTick(function () {
process.nextTick(self.longPoll.bind(self));
});
self.emit('stream:error', serr, err);
self.disconnect();
}
}).catch(function (err) {
self.hasStream = false;
var serr = new self.stanzas.StreamError({
condition: 'connection-timeout'
});
self.emit('stream:error', serr, err);
self.disconnect();
});

ticket.request = req;

req.then(function (body) {
self.emit('raw:incoming', new Buffer(body, 'utf8').toString());
});

return req.then(function () {
self.requests = filter(self.requests, function (item) {
return item.id !== ticket.id;
});
// do not (re)start long polling if terminating, or request is pending, or before authentication
if (bosh.type !== 'terminate' && !self.requests.length && self.authenticated) {
// Delay next auto-request by two ticks since we're likely
// to send data anyway next tick.
process.nextTick(function () {
process.nextTick(self.longPoll.bind(self));
});
}
});
return req;
};

module.exports = BOSHConnection;

0 comments on commit c1ba5e0

Please sign in to comment.