From 102ac957964df725da8a719ed09557a17db8c946 Mon Sep 17 00:00:00 2001 From: Ian Allen Date: Sun, 13 Oct 2024 20:55:37 -0300 Subject: [PATCH] Fix error reading array that could be undefined. Cannot read properties of undefined (reading 'length') --- .../components/common/ows/OWSService.js | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/web-ui/src/main/resources/catalog/components/common/ows/OWSService.js b/web-ui/src/main/resources/catalog/components/common/ows/OWSService.js index 41af26d5f55..7da4b94877d 100644 --- a/web-ui/src/main/resources/catalog/components/common/ows/OWSService.js +++ b/web-ui/src/main/resources/catalog/components/common/ows/OWSService.js @@ -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]); + } + }); + } } } }