Skip to content

Commit ae02a00

Browse files
authored
feat(utils): Kill some dead code branches in XHR instrumentation (#4331)
1 parent 7f1fe2d commit ae02a00

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

packages/utils/src/instrument.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ function instrumentXHR(): void {
226226
// eslint-disable-next-line @typescript-eslint/no-this-alias
227227
const xhr = this;
228228
const url = args[1];
229-
xhr.__sentry_xhr__ = {
229+
const xhrInfo: SentryWrappedXMLHttpRequest['__sentry_xhr__'] = (xhr.__sentry_xhr__ = {
230230
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
231231
method: isString(args[0]) ? args[0].toUpperCase() : args[0],
232232
url: args[1],
233-
};
233+
});
234234

235235
// if Sentry key appears in URL, don't capture it as a request
236236
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
237-
if (isString(url) && xhr.__sentry_xhr__.method === 'POST' && url.match(/sentry_key/)) {
237+
if (isString(url) && xhrInfo.method === 'POST' && url.match(/sentry_key/)) {
238238
xhr.__sentry_own_request__ = true;
239239
}
240240

@@ -243,9 +243,7 @@ function instrumentXHR(): void {
243243
try {
244244
// touching statusCode in some platforms throws
245245
// an exception
246-
if (xhr.__sentry_xhr__) {
247-
xhr.__sentry_xhr__.status_code = xhr.status;
248-
}
246+
xhrInfo.status_code = xhr.status;
249247
} catch (e) {
250248
/* do nothing */
251249
}
@@ -256,8 +254,8 @@ function instrumentXHR(): void {
256254
// Make sure to pop both key and value to keep it in sync.
257255
requestKeys.splice(requestPos);
258256
const args = requestValues.splice(requestPos)[0];
259-
if (xhr.__sentry_xhr__ && args[0] !== undefined) {
260-
xhr.__sentry_xhr__.body = args[0] as XHRSendInput;
257+
if (args[0] !== undefined) {
258+
xhrInfo.body = args[0] as XHRSendInput;
261259
}
262260
}
263261
} catch (e) {

0 commit comments

Comments
 (0)