Fix uncaught promise error in search results

Sentry issue IMPRESS-2020-20 doesn't have a clear backtrace, but it looks like the usual thing where we trigger an Apollo query directly, and forget to catch a potential error in the returned promise. I noticed that the last thing the user did was type in the search bar, and got a _caught_ error for the initial search!

Scanning the SearchPanel file, I think it's likely that this was a failure in `fetchMore` for the infinite pagination.

I'm a bit worried as to _why_ we were doing infinite scrolling stuff when there were no results? I wasn't able to repro a scroll event on the empty results list, but it's plausible that it could happen. I've added a gate to not send this request when there's an error!
This commit is contained in:
Emi Matchu 2021-02-01 19:06:19 -08:00
parent 05282f4b7b
commit 33353e5328

View file

@ -372,7 +372,7 @@ function useSearchResults(query, outfitState) {
// When SearchResults calls this, we'll resend the query, with the `offset`
// increased. We'll append the results to the original query!
const fetchMore = React.useCallback(() => {
if (!loadingGQL && !isEndOfResults) {
if (!loadingGQL && !error && !isEndOfResults) {
fetchMoreGQL({
variables: {
offset: items.length,
@ -402,9 +402,11 @@ function useSearchResults(query, outfitState) {
},
};
},
}).catch((e) => {
console.error("Error loading more search results pages", e);
});
}
}, [loadingGQL, isEndOfResults, fetchMoreGQL, items.length]);
}, [loadingGQL, error, isEndOfResults, fetchMoreGQL, items.length]);
return { loading, loadingMore, error, items, fetchMore };
}