Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

fix(formatHit): fixed npe, not all hits have a country #292

Merged
merged 1 commit into from
Jul 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/formatHit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import findCountryCode from './findCountryCode.js';
import findType from './findType.js';

function getBestHighlightedForm(highlightedValues) {
if (highlightedValues.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the API sometimes send _highlightResult.locale_names = []?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't but I prefer having too much safety checks

Copy link
Contributor

@vvo vvo Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I would remove it then. I feel like everytime we do this, it leads to defensive programming, dead code + FUD (= we will keep this code, just in case)

return undefined;
}
const defaultValue = highlightedValues[0].value;
// collect all other matches
const bestAttributes = [];
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am adding a test for that one, but for the previous one I don't know the usecase

};

const suggestion = {
Expand Down