From 3cd5de13e06e46f59b400506360fb45b405d6e70 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 17 Dec 2021 16:53:52 +0100 Subject: [PATCH] feat(utils): Kill some dead code branches in XHR instrumentation --- packages/utils/src/instrument.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/utils/src/instrument.ts b/packages/utils/src/instrument.ts index 5b96eea11a2b..8dd358c484e0 100644 --- a/packages/utils/src/instrument.ts +++ b/packages/utils/src/instrument.ts @@ -226,15 +226,15 @@ function instrumentXHR(): void { // eslint-disable-next-line @typescript-eslint/no-this-alias const xhr = this; const url = args[1]; - xhr.__sentry_xhr__ = { + const xhrInfo: SentryWrappedXMLHttpRequest['__sentry_xhr__'] = (xhr.__sentry_xhr__ = { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access method: isString(args[0]) ? args[0].toUpperCase() : args[0], url: args[1], - }; + }); // if Sentry key appears in URL, don't capture it as a request // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - if (isString(url) && xhr.__sentry_xhr__.method === 'POST' && url.match(/sentry_key/)) { + if (isString(url) && xhrInfo.method === 'POST' && url.match(/sentry_key/)) { xhr.__sentry_own_request__ = true; } @@ -243,9 +243,7 @@ function instrumentXHR(): void { try { // touching statusCode in some platforms throws // an exception - if (xhr.__sentry_xhr__) { - xhr.__sentry_xhr__.status_code = xhr.status; - } + xhrInfo.status_code = xhr.status; } catch (e) { /* do nothing */ } @@ -256,8 +254,8 @@ function instrumentXHR(): void { // Make sure to pop both key and value to keep it in sync. requestKeys.splice(requestPos); const args = requestValues.splice(requestPos)[0]; - if (xhr.__sentry_xhr__ && args[0] !== undefined) { - xhr.__sentry_xhr__.body = args[0] as XHRSendInput; + if (args[0] !== undefined) { + xhrInfo.body = args[0] as XHRSendInput; } } } catch (e) {