diff --git a/src/formatHit.js b/src/formatHit.js index 35e795b24..db35e4d36 100644 --- a/src/formatHit.js +++ b/src/formatHit.js @@ -2,6 +2,9 @@ import findCountryCode from './findCountryCode.js'; import findType from './findType.js'; function getBestHighlightedForm(highlightedValues) { + if (highlightedValues.length === 0) { + return undefined; + } const defaultValue = highlightedValues[0].value; // collect all other matches const bestAttributes = []; @@ -46,7 +49,7 @@ export default function formatHit({ name: getBestHighlightedForm(hit._highlightResult.locale_names), city: city ? getBestHighlightedForm(hit._highlightResult.city) : undefined, administrative: administrative ? getBestHighlightedForm(hit._highlightResult.administrative) : undefined, - country: hit._highlightResult.country.value + country: country ? hit._highlightResult.country.value : undefined }; const suggestion = {