Skip to content

Commit

Permalink
Fix error reading array that could be undefined.
Browse files Browse the repository at this point in the history
   Cannot read properties of undefined (reading 'length')
  • Loading branch information
ianwallen committed Oct 13, 2024
1 parent 9afd1bf commit 102ac95
Showing 1 changed file with 38 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,46 +582,48 @@
var needles = [];
var layers = capObj.featureTypeList.featureType;

for (var i = 0, len = layers.length; i < len; i++) {
//check layername
if (
name == layers[i].name.localPart ||
name == layers[i].name.prefix + ":" + layers[i].name.localPart ||
name == layers[i].Name
) {
needles.push(layers[i]);
continue;
}
if (Array.isArray(layers)) {
for (var i = 0, len = layers.length; i < len; i++) {
//check layername
if (
name == layers[i].name.localPart ||
name == layers[i].name.prefix + ":" + layers[i].name.localPart ||
name == layers[i].Name
) {
needles.push(layers[i]);
continue;
}

//check title
if (name == layers[i].title || name == layers[i].Title) {
needles.push(layers[i]);
continue;
}
//check title
if (name == layers[i].title || name == layers[i].Title) {
needles.push(layers[i]);
continue;
}

//check dataset identifer match
if (uuid != null) {
if (angular.isArray(layers[i].Identifier)) {
angular.forEach(layers[i].Identifier, function (id) {
if (id == uuid) {
needles.push(layers[i]);
}
});
//check dataset identifer match
if (uuid != null) {
if (angular.isArray(layers[i].Identifier)) {
angular.forEach(layers[i].Identifier, function (id) {
if (id == uuid) {
needles.push(layers[i]);
}
});
}
}
}

//check uuid from metadata url
if (uuid != null) {
if (angular.isArray(layers[i].MetadataURL)) {
angular.forEach(layers[i].MetadataURL, function (mdu) {
if (
mdu &&
mdu.OnlineResource &&
mdu.OnlineResource.indexOf(uuid) > 0
) {
needles.push(layers[i]);
}
});
//check uuid from metadata url
if (uuid != null) {
if (angular.isArray(layers[i].MetadataURL)) {
angular.forEach(layers[i].MetadataURL, function (mdu) {
if (
mdu &&
mdu.OnlineResource &&
mdu.OnlineResource.indexOf(uuid) > 0
) {
needles.push(layers[i]);
}
});
}
}
}
}
Expand Down

0 comments on commit 102ac95

Please sign in to comment.