Skip to content

Commit d579da9

Browse files
authored
Merge pull request #11753 from google/enhancement/8970-fix-duplicate-errors
2 parents 12d8036 + 30e5b04 commit d579da9

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

assets/js/components/ReportError.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { uniqWith } from 'lodash';
2727
*/
2828
import { Fragment } from '@wordpress/element';
2929
import { __, sprintf } from '@wordpress/i18n';
30+
import { removeQueryArgs } from '@wordpress/url';
3031

3132
/**
3233
* Internal dependencies
@@ -92,7 +93,12 @@ export default function ReportError( { moduleSlug, error } ) {
9293
errors.map( ( err ) => ( {
9394
...err,
9495
message: getMessage( err ),
95-
reconnectURL: err.data?.reconnectURL,
96+
// The `code` parameter contains a session ID which can vary
97+
// between requests, so we ignore it for comparison below.
98+
// To use the original `reconnectURL` elsewhere, use `err.data.reconnectURL`.
99+
reconnectURL: err.data?.reconnectURL
100+
? removeQueryArgs( err.data.reconnectURL, 'code' )
101+
: undefined,
96102
} ) ),
97103
( errorA, errorB ) =>
98104
errorA.message === errorB.message &&

assets/js/components/ReportError.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,59 @@ describe( 'ReportError', () => {
571571
expect( invalidateResolutionSpy ).toHaveBeenCalledTimes( 4 );
572572
} );
573573

574+
it( 'should not list error descriptions with the same `reconnectURL`s', async () => {
575+
const { container, waitForRegistry } = render(
576+
<ReportError
577+
moduleSlug={ moduleName }
578+
error={ [
579+
{
580+
code: 'test_error',
581+
message: 'Test error message',
582+
data: {
583+
reason: '',
584+
reconnectURL: 'https://example.com/page?code=1',
585+
status: 401,
586+
},
587+
},
588+
{
589+
code: 'test_error',
590+
message: 'Test error message',
591+
data: {
592+
reason: '',
593+
reconnectURL: 'https://example.com/page?code=2',
594+
status: 401,
595+
},
596+
},
597+
{
598+
code: 'test_error',
599+
message: 'Test error message 2',
600+
data: {
601+
reason: '',
602+
reconnectURL: 'https://example.com/page2?code=1',
603+
status: 401,
604+
},
605+
},
606+
] }
607+
/>,
608+
{
609+
registry,
610+
}
611+
);
612+
613+
await waitForRegistry();
614+
615+
const errorDescriptionElement = container.querySelectorAll(
616+
'.googlesitekit-cta__description'
617+
);
618+
619+
// Verify the child element count for the error description element is two.
620+
// However, the passed error array has three repetitive error objects.
621+
// The second error is not listed because it has the same `message` and `reconnectURL`
622+
// as the first one. Note that the `code` query parameter in the `reconnectURL` is
623+
// ignored for comparison, as it is expected to be different for each URL.
624+
expect( errorDescriptionElement[ 0 ].childElementCount ).toBe( 2 );
625+
} );
626+
574627
it( 'should render `Get help` link without prefix text on non-retryable error', async () => {
575628
await registry.dispatch( MODULES_ANALYTICS_4 ).receiveError(
576629
{

0 commit comments

Comments
 (0)