Skip to content

Commit

Permalink
allow search to occur if "near me" request fails (#1668)
Browse files Browse the repository at this point in the history
this pr update the middleware function `promptForLocation` to gracefully handle rejected promises related to fetching near me intents or getting user location. 

If fails, a search request should still get executed. To do so, catch in the then() call chain to handle rejected promise cases and provide a console warn message. Since the handler function doesn't return anything, the promise returned by then gets resolved with an undefined value.


J=SLAP-1885
TEST=manual

return a rejected promise for `fetchQueryIntents` function to mock a failed autocomplete request to compute near me intents. See that a console warn message appear indicating the error, but the search is still executed and see that results for the query is shown on page.
  • Loading branch information
yen-tt committed Feb 14, 2022
1 parent 9aa76ef commit 81fe307
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ui/components/search/searchcomponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,10 @@ export default class SearchComponent extends Component {
promptForLocation (query) {
if (this._promptForLocation) {
return this.fetchQueryIntents(query)
.then(queryIntents => queryIntents.includes('NEAR_ME'))
.then(
queryIntents => queryIntents.includes('NEAR_ME'),
error => Promise.reject(new Error('Failed to fetch query intents.', { cause: error }))
)
.then(queryHasNearMeIntent => {
if (queryHasNearMeIntent && !this.core.storage.get(StorageKeys.GEOLOCATION)) {
return new Promise((resolve, reject) =>
Expand All @@ -604,7 +607,8 @@ export default class SearchComponent extends Component {
this._geolocationOptions)
);
}
});
})
.catch(error => console.warn('Unable to determine user\'s location.', error));
} else {
return Promise.resolve();
}
Expand Down

0 comments on commit 81fe307

Please sign in to comment.