From 33353e5328e830e255937e4e114d33c649863506 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 1 Feb 2021 19:06:19 -0800 Subject: [PATCH] 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! --- src/app/WardrobePage/SearchPanel.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/WardrobePage/SearchPanel.js b/src/app/WardrobePage/SearchPanel.js index da12706..64f6fab 100644 --- a/src/app/WardrobePage/SearchPanel.js +++ b/src/app/WardrobePage/SearchPanel.js @@ -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 }; }