Fix `json-prune-xhr-response` as per feedback

Related commit:
abe41034f6
This commit is contained in:
Raymond Hill 2023-09-06 13:04:43 -04:00
parent 5c9c0a8023
commit 14d60ac5d3
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 26 additions and 10 deletions

View File

@ -1365,25 +1365,41 @@ function jsonPruneXhrResponse(
if ( xhrDetails === undefined ) {
return innerResponse;
}
if ( typeof innerResponse !== 'object' ) {
xhrDetails.response = innerResponse;
if ( xhrDetails.response !== undefined ) {
return xhrDetails.response;
}
let outerResponse = xhrDetails.response;
if ( outerResponse !== undefined ) {
return outerResponse;
let objBefore;
if ( typeof innerResponse === 'object' ) {
objBefore = innerResponse;
} else if ( typeof innerResponse === 'string' ) {
try { objBefore = safe.jsonParse(innerResponse); }
catch(ex) { }
}
outerResponse = objectPrune(
innerResponse,
if ( typeof objBefore !== 'object' ) {
return (xhrDetails.response = innerResponse);
}
const objAfter = objectPrune(
objBefore,
rawPrunePaths,
rawNeedlePaths,
{ matchAll: true },
extraArgs
);
if ( typeof outerResponse !== 'object' ) {
let outerResponse;
if ( typeof objAfter === 'object' ) {
outerResponse = typeof innerResponse === 'string'
? safe.jsonStringify(objAfter)
: objAfter;
} else {
outerResponse = innerResponse;
}
xhrDetails.response = outerResponse;
return outerResponse;
return (xhrDetails.response = outerResponse);
}
get responseText() {
const response = this.response;
return typeof response !== 'string'
? super.responseText
: response;
}
};
}