Skip to content

Commit 9d93bc8

Browse files
Address review.
1 parent 4c1236f commit 9d93bc8

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
lines changed

assets/js/components/ReportError.js

Lines changed: 7 additions & 4 deletions
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
@@ -39,7 +40,6 @@ import {
3940
} from '@/js/util/errors';
4041
import { getInsufficientPermissionsErrorDescription } from '@/js/util/insufficient-permissions-error-description';
4142
import { purify } from '@/js/util/purify';
42-
import { removeParamFromURL } from '@/js/util/urls';
4343
import CTA from './notifications/CTA';
4444
import ReportErrorActions from './ReportErrorActions';
4545
import useViewOnly from '@/js/hooks/useViewOnly';
@@ -93,12 +93,15 @@ export default function ReportError( { moduleSlug, error } ) {
9393
errors.map( ( err ) => ( {
9494
...err,
9595
message: getMessage( err ),
96-
reconnectURL: err.data?.reconnectURL,
96+
// The `code` parameter contains a session ID which can vary
97+
// between requests, so we ignore it when comparing.
98+
reconnectURL: err.data?.reconnectURL
99+
? removeQueryArgs( err.data?.reconnectURL, 'code' )
100+
: undefined,
97101
} ) ),
98102
( errorA, errorB ) =>
99103
errorA.message === errorB.message &&
100-
removeParamFromURL( errorA.reconnectURL, 'code' ) ===
101-
removeParamFromURL( errorB.reconnectURL, 'code' )
104+
errorA.reconnectURL === errorB.reconnectURL
102105
);
103106

104107
const hasInsufficientPermissionsError = errors.some( ( err ) =>

assets/js/components/ReportError.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ describe( 'ReportError', () => {
571571
expect( invalidateResolutionSpy ).toHaveBeenCalledTimes( 4 );
572572
} );
573573

574-
it( 'should group errors based on `reconnectURL`', async () => {
574+
it( 'it should not list error descriptions with the same `reconnectURL`s', async () => {
575575
const { container } = render(
576576
<ReportError
577577
moduleSlug={ moduleName }

assets/js/util/urls.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,3 @@ export function shortenURL( url, maxChars ) {
118118
const extraChars = shortenedURL.length - Math.floor( maxChars ) + 1; // 1 is the length of "…".
119119
return '…' + shortenedURL.substr( extraChars );
120120
}
121-
122-
/**
123-
* Removes a query parameter from a URL.
124-
*
125-
* @since n.e.x.t
126-
*
127-
* @param {string} url The URL to remove the query parameter from.
128-
* @param {string} param The query parameter to remove.
129-
* @return {string} The URL without the query param.
130-
*/
131-
export function removeParamFromURL( url, param ) {
132-
// Wrapped in try catch to avoid exceptions in the rare case the URL is invalid.
133-
try {
134-
const urlObject = new URL( url );
135-
urlObject.searchParams.delete( param );
136-
return urlObject.toString();
137-
} catch {
138-
return url;
139-
}
140-
}

0 commit comments

Comments
 (0)