Commit 9f6b2ae1 authored by Markus Opolka's avatar Markus Opolka
Browse files

Add error handling for feature search

parent c5ae154d
......@@ -6,7 +6,7 @@ function findKeyRecursive (object, keytofind, ret = []) {
* Finds all keys in a nested object and returns them as an array
*/
var value
let value
Object.keys(object).forEach(function (key) {
if (key === keytofind) {
......@@ -88,12 +88,19 @@ function searchInFeatures (features, query) {
* Attributes must be in _attributes
*/
var results = []
var reCat = new RegExp(query.category)
var reType = new RegExp(query.type)
var reSub = new RegExp(query.subtype)
let results = []
for (var idx = 0; idx < features.length; idx++) {
try {
var reCat = new RegExp(query.category)
var reType = new RegExp(query.type)
var reSub = new RegExp(query.subtype)
} catch (err) {
console.log(arguments.callee) // eslint-disable-line no-caller
console.log('>> Error while searching features')
return results
}
for (let idx = 0; idx < features.length; idx++) {
var matchCat = reCat.test(features[idx]._attributes.category)
var matchType = reType.test(features[idx]._attributes.type)
var matchSub = reSub.test(features[idx]._attributes.subtype)
......@@ -114,8 +121,8 @@ function searchFeaturesInDocument (document, query) {
if (typeof query.type === 'undefined') { query.type = '.*' }
if (typeof query.subtype === 'undefined') { query.subtype = '.*' }
var features = findKeyRecursive(document, 'feature')
var results = searchInFeatures(features, query)
let features = findKeyRecursive(document, 'feature')
let results = searchInFeatures(features, query)
if (results.length > 0) {
document['count'] = countReferences(results)
......@@ -139,7 +146,7 @@ function searchInDocument (document, query) {
console.log(arguments.callee) // eslint-disable-line no-caller
console.log('>> Error while searching')
}
var results = searchInObject(flatobject, query)
let results = searchInObject(flatobject, query)
if (results.length > 0) {
document['results'] = results
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment