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

Commit

Permalink
fix(api): handle strange api responses, log them
Browse files Browse the repository at this point in the history
  • Loading branch information
vvo committed Apr 7, 2016
1 parent 643c57b commit 8dad71c
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/createHitFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@ import findCountryCode from './findCountryCode.js';

export default function createHitFormatter({formatAutocompleteSuggestion, formatInputValue}) {
return hit => {
let suggestion = {
administrative: hit.administrative && hit.administrative[0],
city: hit.city && hit.city[0],
country: hit.country,
countryCode: findCountryCode(hit._tags),
isCity: hit.is_city,
lat: hit._geoloc[0].lat,
lng: hit._geoloc[0].lng,
name: hit.locale_names[0].trim() // trim should be done in data, waiting for a fix in Places API,
};
try {
let suggestion = {
administrative: hit.administrative && hit.administrative[0],
city: hit.city && hit.city[0],
country: hit.country,
countryCode: findCountryCode(hit._tags),
isCity: hit.is_city,
lat: hit._geoloc[0].lat,
lng: hit._geoloc[0].lng,
name: hit.locale_names[0].trim() // trim should be done in data, waiting for a fix in Places API,
};

// this is the value to put inside the input.value
// autocomplete.js automatically takes hit.value as the underlying
// input value when a suggestion is validated with enter or selected with the mouse
suggestion._inputValue = formatInputValue(suggestion);
// this is the value to put inside the input.value
// autocomplete.js automatically takes hit.value as the underlying
// input value when a suggestion is validated with enter or selected with the mouse
suggestion._inputValue = formatInputValue(suggestion);

// this is the value shown in suggestions, we highlight the name
suggestion._dropdownHTMLFormatted = formatAutocompleteSuggestion({
...suggestion,
name: hit._highlightResult.locale_names[0].value.trim()
});
// this is the value shown in suggestions, we highlight the name
suggestion._dropdownHTMLFormatted = formatAutocompleteSuggestion({
...suggestion,
name: hit._highlightResult.locale_names[0].value.trim()
});

return suggestion;
return suggestion;
} catch (e) {
/* eslint no-console: 0 */
console.error('Could not parse object', hit);
console.error(e);
}
};
}

0 comments on commit 8dad71c

Please sign in to comment.