mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-17 06:13:11 +01:00
Graceful handling of JSON parse errors from Indigo responses.
Make initial discover queries serialized to not overwhelm slow Indigo servers.
This commit is contained in:
@@ -68,7 +68,7 @@ IndigoPlatform.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var json = JSON.parse(body);
|
var json = JSON.parse(body);
|
||||||
async.each(json, function(item, asyncCallback) {
|
async.eachSeries(json, function(item, asyncCallback) {
|
||||||
var deviceURL = that.baseURL + item.restURL;
|
var deviceURL = that.baseURL + item.restURL;
|
||||||
var deviceOptions = {
|
var deviceOptions = {
|
||||||
url: deviceURL,
|
url: deviceURL,
|
||||||
@@ -81,15 +81,19 @@ IndigoPlatform.prototype = {
|
|||||||
request(deviceOptions, function(deviceError, deviceResponse, deviceBody) {
|
request(deviceOptions, function(deviceError, deviceResponse, deviceBody) {
|
||||||
if (deviceError) {
|
if (deviceError) {
|
||||||
console.trace("Requesting Indigo device info: " + deviceURL + "\nError: " + deviceError + "\nResponse: " + deviceBody);
|
console.trace("Requesting Indigo device info: " + deviceURL + "\nError: " + deviceError + "\nResponse: " + deviceBody);
|
||||||
asyncCallback(deviceError)
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var deviceJson = JSON.parse(deviceBody);
|
try {
|
||||||
that.log("Discovered " + deviceJson.type + ": " + deviceJson.name);
|
var deviceJson = JSON.parse(deviceBody);
|
||||||
that.foundAccessories.push(
|
that.log("Discovered " + deviceJson.type + ": " + deviceJson.name);
|
||||||
new IndigoAccessory(that.log, that.auth, deviceURL, deviceJson));
|
that.foundAccessories.push(
|
||||||
asyncCallback();
|
new IndigoAccessory(that.log, that.auth, deviceURL, deviceJson));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
that.log("Error parsing Indigo device info: " + deviceURL + "\nException: " + e + "\nResponse: " + deviceBody);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
asyncCallback();
|
||||||
});
|
});
|
||||||
}, function(asyncError) {
|
}, function(asyncError) {
|
||||||
// This will be called after all the requests complete
|
// This will be called after all the requests complete
|
||||||
@@ -135,11 +139,18 @@ IndigoAccessory.prototype = {
|
|||||||
if (error) {
|
if (error) {
|
||||||
console.trace("Requesting Device Status.");
|
console.trace("Requesting Device Status.");
|
||||||
that.log(error);
|
that.log(error);
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
that.log("getStatus of " + that.name + ": " + body);
|
that.log("getStatus of " + that.name + ": " + body);
|
||||||
callback(JSON.parse(body));
|
try {
|
||||||
|
var json = JSON.parse(body);
|
||||||
|
callback(json);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.trace("Requesting Device Status.");
|
||||||
|
that.log("Exception: " + e + "\nResponse: " + body);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user