From 81fe3076c4e36799d02d0300838929dd77fcdddc Mon Sep 17 00:00:00 2001 From: Yen Truong <36055303+yen-tt@users.noreply.github.com> Date: Mon, 14 Feb 2022 11:00:46 -0500 Subject: [PATCH] allow search to occur if "near me" request fails (#1668) 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. --- src/ui/components/search/searchcomponent.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ui/components/search/searchcomponent.js b/src/ui/components/search/searchcomponent.js index e4432316f..126464110 100644 --- a/src/ui/components/search/searchcomponent.js +++ b/src/ui/components/search/searchcomponent.js @@ -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) => @@ -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(); }