Skip to content

Commit

Permalink
Analytics: Handle JSON stringify errors (#98467)
Browse files Browse the repository at this point in the history
tyxla authored Jan 16, 2025
1 parent eeaceaa commit e7b7075
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions client/lib/analytics/ad-tracking/debug.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
export function circularReferenceSafeJSONStringify( json, space ) {
let cache = [];
const str = JSON.stringify(
json,
function ( key, value ) {
if ( typeof value === 'object' && value !== null ) {
if ( cache.indexOf( value ) !== -1 ) {
return 'Circular reference';
try {
let cache = [];
const str = JSON.stringify(
json,
function ( key, value ) {
if ( typeof value === 'object' && value !== null ) {
if ( cache.indexOf( value ) !== -1 ) {
return 'Circular reference';
}
cache.push( value );
}
cache.push( value );
}
return value;
},
space
);
cache = null;
return str;
return value;
},
space
);
cache = null;
return str;
} catch ( e ) {
return 'Error: ' + e.message;
}
}

0 comments on commit e7b7075

Please sign in to comment.