Skip to content

Commit

Permalink
ref(replay): Add further logging to network body parsing (#9566)
Browse files Browse the repository at this point in the history
We got somewhat closer to figuring out the problem there. Based on this
comment:
#9339 (comment)

> The requests are now showing with the request body, but the response
body is "undefined"

It seems that the problem is with parsing the response body for a XHR
request. I added some more logging there, to be able to debug this
further.
  • Loading branch information
mydea authored Nov 16, 2023
1 parent e4cd09c commit 5698094
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/replay/src/coreHandlers/util/networkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export function getBodyString(body: unknown): string | undefined {
__DEBUG_BUILD__ && logger.warn('[Replay] Failed to serialize body', body);
}

__DEBUG_BUILD__ && logger.info('[Replay] Skipping network body because of body type', body);

return undefined;
}

Expand Down
13 changes: 11 additions & 2 deletions packages/replay/src/coreHandlers/util/xhrUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,24 @@ function getResponseHeaders(xhr: XMLHttpRequest): Record<string, string> {
}

function _getXhrResponseBody(xhr: XMLHttpRequest): string | undefined {
// We collect errors that happen, but only log them if we can't get any response body
const errors: unknown[] = [];

try {
return xhr.responseText;
} catch {} // eslint-disable-line no-empty
} catch (e) {
errors.push(e);
}

// Try to manually parse the response body, if responseText fails
try {
const response = xhr.response;
return getBodyString(response);
} catch {} // eslint-disable-line no-empty
} catch (e) {
errors.push(e);
}

__DEBUG_BUILD__ && logger.warn('[Replay] Failed to get xhr response body', ...errors);

return undefined;
}

0 comments on commit 5698094

Please sign in to comment.