Protect against cache lookup returning null

If the cache file does not exist _cacheGetJson will not pass any value to the callback.

In the getImage function the callback passed to _cacheGetJson assumes if there was no error value then the second argument must be an array.

Add some logic to guard against null values before iterating over the array.
This commit is contained in:
Kris Shannon 2016-02-15 03:58:29 +11:00
parent 6397c8bade
commit 52fc48b3e9

View File

@ -354,12 +354,14 @@ TritonApi.prototype.getImage = function getImage(opts, cb) {
next(err);
return;
}
if (images) {
for (var i = 0; i < images.length; i++) {
if (images[i].id === opts.name) {
img = images[i];
break;
}
}
}
next();
});
},