From c491a00a8f407c3f6bff11c9d83283e0ce229099 Mon Sep 17 00:00:00 2001 From: Christos Paschalidis Date: Thu, 25 Mar 2021 15:58:51 +0000 Subject: [PATCH] fix: the bug (#1580) --- .../Pages/Search/SearchForm/SearchForm.epics.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/core_modules/capture-core/components/Pages/Search/SearchForm/SearchForm.epics.js b/src/core_modules/capture-core/components/Pages/Search/SearchForm/SearchForm.epics.js index 4fce506fed..1f66129b18 100644 --- a/src/core_modules/capture-core/components/Pages/Search/SearchForm/SearchForm.epics.js +++ b/src/core_modules/capture-core/components/Pages/Search/SearchForm/SearchForm.epics.js @@ -59,6 +59,14 @@ const getFiltersForAttributesSearchQuery = (formValues) => { return [...stringFilters, ...rangeFilers]; }; + +const handleErrors = ({ httpStatusCode, message }) => { + if (httpStatusCode === 409 && message === 'maxteicountreached') { + return of(showTooManyResultsViewOnSearchPage()); + } + return of(showErrorViewOnSearchPage()); +}; + const searchViaAttributesStream = (queryArgs, attributes, triggeredFrom) => from(getTrackedEntityInstances(queryArgs, attributes)).pipe( map(({ trackedEntityInstanceContainers: searchResults, pagingData }) => { @@ -79,12 +87,7 @@ const searchViaAttributesStream = (queryArgs, attributes, triggeredFrom) => return showEmptyResultsViewOnSearchPage(); }), startWith(showLoadingViewOnSearchPage()), - catchError(({ httpStatusCode, message }) => { - if (httpStatusCode === 409 && message === 'maxteicountreached') { - return of(showTooManyResultsViewOnSearchPage()); - } - return of(showErrorViewOnSearchPage()); - }), + catchError(handleErrors), ); export const searchViaUniqueIdOnScopeProgramEpic: Epic = (action$, store) => @@ -259,7 +262,7 @@ export const fallbackSearchEpic: Epic = (action$: InputObservable) => return of(showEmptyResultsViewOnSearchPage()); }), startWith(showLoadingViewOnSearchPage()), - catchError(() => of(showErrorViewOnSearchPage())), + catchError(handleErrors), ); }), );