Skip to content

Commit

Permalink
issue #15
Browse files Browse the repository at this point in the history
Resend bridge request after 300ms on ECONNRESET
  • Loading branch information
ebaauw committed Nov 14, 2016
1 parent f21c900 commit 67f8cab
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/HueBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,19 @@ HueBridge.prototype.request = function(method, resource, body) {
this.log.debug("%s: hue bridge request: %s", this.name, requestString);
request(requestObj, function(err, response, responseBody) {
if (err) {
this.log.error("%s: hue bridge communication error %s", this.name, err);
return reject(err);
if (err.code === "ECONNRESET") {
this.log.debug("%s: hue bridge communication error %s - retrying in 300ms", this.name, err.code);
setTimeout(function () {
resolve(this.request(method, resource, body));
}.bind(this), 300);
return;
}
this.log.error("%s: hue bridge communication error %s", this.name, err.code);
return reject(err.code);
}
if (response.statusCode != 200) {
this.log.error("%s: hue bridge status %s", this.name, response.statusCode);
return reject(err);
return reject(response.statusCode);
}
// this.log.debug("%s: hue bridge response: %s", this.name, responseBody);
var obj;
Expand All @@ -305,11 +312,11 @@ HueBridge.prototype.request = function(method, resource, body) {
}
if (util.isArray(obj)) {
for (let id in obj) {
let e = obj[id].error;
if (e) {
this.log.error("%s: hue bridge error %d: %s", this.name, e.type, e.description);
return reject(e.type);
}
let e = obj[id].error;
if (e) {
this.log.error("%s: hue bridge error %d: %s", this.name, e.type, e.description);
return reject(e.type);
}
}
}
return resolve(obj);
Expand Down

0 comments on commit 67f8cab

Please sign in to comment.