From 43791e104713db318d5c4996d041dfbacf3cbcd2 Mon Sep 17 00:00:00 2001 From: Dmytro-Melnyshyn Date: Mon, 2 Sep 2024 15:56:13 +0300 Subject: [PATCH] STSMACOM-851: Return a specific 400 error message in StripesConnectedSource. --- CHANGELOG.md | 1 + .../ConnectedSource/StripesConnectedSource.js | 9 ++++++- .../tests/StripesConnectedSource-test.js | 26 ++++++++++++++++++- translations/stripes-smart-components/en.json | 1 + 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd806fdbe..2ca7b3d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ * Provide `startLabel` and `endLabel` props in `` to enable unique accessible labeling. STSMACOM-848. * Add `showSortIndicator` prop to `SearchAndSort` to display sort indicator next to the column names. STSMACOM-849. * Trim value to validate required field in the `ControlledVocab` component. STSMACOM-850. +* Return a specific 400 error message in `StripesConnectedSource`. STSMACOM-851. ## [9.1.1] (IN PROGRESS) diff --git a/lib/SearchAndSort/ConnectedSource/StripesConnectedSource.js b/lib/SearchAndSort/ConnectedSource/StripesConnectedSource.js index a7c0654c2..5ee286baa 100644 --- a/lib/SearchAndSort/ConnectedSource/StripesConnectedSource.js +++ b/lib/SearchAndSort/ConnectedSource/StripesConnectedSource.js @@ -66,7 +66,10 @@ export default class StripesConnectedSource { } failureMessage() { - const { isRequestUrlExceededLimit } = this.props; + const { + isRequestUrlExceededLimit, + parentResources, + } = this.props; const failed = this.recordsObj.failed; @@ -74,6 +77,10 @@ export default class StripesConnectedSource { return ; } + if (failed.httpStatus === 400) { + return ; + } + // stripes-connect failure object has: dataKey, httpStatus, message, module, resource, throwErrors const res = `Error ${failed.httpStatus}: ${failed.message.replace(/.*:\s*/, '')}`; this.logger.log('source', 'failureMessage', res); diff --git a/lib/SearchAndSort/tests/StripesConnectedSource-test.js b/lib/SearchAndSort/tests/StripesConnectedSource-test.js index 289842a12..c136d3203 100644 --- a/lib/SearchAndSort/tests/StripesConnectedSource-test.js +++ b/lib/SearchAndSort/tests/StripesConnectedSource-test.js @@ -7,7 +7,7 @@ import { expect } from 'chai'; import StripesConnectedSource from '../ConnectedSource/StripesConnectedSource'; import { REQUEST_URL_LIMIT } from '../requestUrlLimit'; -describe('StripesConnectedSource', () => { +describe.only('StripesConnectedSource', () => { describe('when a request URL is too long', () => { it('should display an error message', () => { expect(new StripesConnectedSource({ isRequestUrlExceededLimit: true }).failureMessage().props).to.deep.equal({ @@ -18,4 +18,28 @@ describe('StripesConnectedSource', () => { }); }); }); + + it('should return a specific 400 error message', () => { + const query = 'www.itemcase.com/test/uri'; + + const props = { + parentResources: { + records: { + failed: { + httpStatus: 400, + }, + }, + query: { + query, + }, + }, + }; + + expect(new StripesConnectedSource(props).failureMessage().props).to.deep.equal({ + id: 'stripes-smart-components.error.badRequest', + values: { + query, + }, + }); + }); }); diff --git a/translations/stripes-smart-components/en.json b/translations/stripes-smart-components/en.json index 9ca57710f..e0a71f717 100644 --- a/translations/stripes-smart-components/en.json +++ b/translations/stripes-smart-components/en.json @@ -283,5 +283,6 @@ "editableList.actionsColumnHeader": "Actions", "editableList.confirmationModal.cancelLabel": "No, do not delete", "editableList.confirmationModal.confirmLabel": "Yes, delete", + "error.badRequest": "Search could not be processed for {query}. Please check your query and try again.", "error.requestUrlLimit": "Search URI request character limit has been exceeded. The character limit is {limit}. Please revise your search and/or facet selections." }