Closed
Description
When using findAll and the resource returns a single object as a result, not an array. Some APIs could work like that if you have filtered or something causing only one answer to be returned from the server instead of returning an array with one element. But this code could fail when that happens because the angular.forEach starts to iterate over the values in the object. And if a value is null the code crashes.
function processResults(utils, data, resourceName, queryHash) {
var resource = this.store[resourceName],
idAttribute = this.definitions[resourceName].idAttribute,
date = new Date().getTime();
data = data || [];
// Query is no longer pending
delete resource.pendingQueries[queryHash];
resource.completedQueries[queryHash] = date;
// Update modified timestamp of collection
resource.collectionModified = utils.updateTimestamp(resource.collectionModified);
// Merge the new values into the cache
var injected = this.inject(resourceName, data);
// Make sure each object is added to completedQueries
angular.forEach(injected, function (item) {
resource.completedQueries[item[idAttribute]] = date;
});
return injected;
}
There should probably be a check to only run the loop if injected is an array, and just run the code on the one object if it is not.