Skip to content

Commit 26de19e

Browse files
authored
UISAUTCOMP-133 Handle uncaught error when a search request fails. (#174)
1 parent 00fdd65 commit 26de19e

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change history for stripes-authoriy-components
22

3+
## [5.0.2] (IN PROGRESS)
4+
5+
- [UISAUTCOMP-133](https://issues.folio.org/browse/UISAUTCOMP-133) Handle uncaught error when a search request fails.
6+
37
## [5.0.1] (https://github.com/folio-org/stripes-authority-components/tree/v5.0.1) (2024-11-14)
48

59
- [UISAUTCOMP-130](https://issues.folio.org/browse/UISAUTCOMP-130) Provide a prop to `<AcqDateRangeFilter>` to subscribe to search form resets.

lib/SearchResultsList/SearchResultsList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ const SearchResultsList = ({
154154
pending: () => loading,
155155
failure: () => error,
156156
failureMessage() {
157-
const status = error.response.status;
157+
const status = error?.response?.status;
158158

159159
if (status === 403) {
160160
return intl.formatMessage({ id: 'stripes-authority-components.authorities.error.forbidden' });
161161
}
162162

163-
return null;
163+
return intl.formatMessage({ id: 'stripes-authority-components.search-results-list.error.badRequest' }, { query });
164164
},
165165
}),
166166
[loading, hasFilters, query, loaded, error, intl],

lib/SearchResultsList/SearchResultsList.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,18 @@ describe('Given SearchResultsList', () => {
287287
expect(getByText('stripes-authority-components.authorities.error.forbidden')).toBeDefined();
288288
});
289289
});
290+
291+
describe('when a search fails due to an unknown http error', () => {
292+
it('should display a generic error message', () => {
293+
const { getByText } = renderSearchResultsList({
294+
authorities: [],
295+
totalResults: 0,
296+
query: 'test=abc',
297+
loaded: true,
298+
error: { response: { status: 400 } },
299+
});
300+
301+
expect(getByText('stripes-authority-components.search-results-list.error.badRequest')).toBeDefined();
302+
});
303+
});
290304
});

translations/stripes-authority-components/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"search-results-list.paneSub": "{totalRecords, number} {totalRecords, plural, one {record found} other {records found}}",
4646
"search-results-list.selectAll": "Unselect all records on this page",
4747
"search-results-list.unselectAll": "Select all records on this page",
48+
"search-results-list.error.badRequest": "Search could not be processed for {query}. Please check your query and try again.",
4849

4950
"authority.view.error.notFound": "Authority record not found",
5051
"authority.view.error.unknown": "An unknown error occurred",

0 commit comments

Comments
 (0)