MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / _wrapXHR

Function _wrapXHR

packages/browser/src/integrations/httpclient.ts:307–335  ·  view source on GitHub ↗

* Wraps XMLHttpRequest to capture request and response data

(client: Client, options: HttpClientOptions)

Source from the content-addressed store, hash-verified

305 * Wraps XMLHttpRequest to capture request and response data
306 */
307function _wrapXHR(client: Client, options: HttpClientOptions): void {
308 if (!('XMLHttpRequest' in GLOBAL_OBJ)) {
309 return;
310 }
311
312 addXhrInstrumentationHandler(handlerData => {
313 if (getClient() !== client) {
314 return;
315 }
316
317 const { error, virtualError } = handlerData;
318
319 const xhr = handlerData.xhr as SentryWrappedXMLHttpRequest & XMLHttpRequest;
320
321 const sentryXhrData = xhr[SENTRY_XHR_DATA_KEY];
322
323 if (!sentryXhrData) {
324 return;
325 }
326
327 const { method, request_headers: headers } = sentryXhrData;
328
329 try {
330 _xhrResponseHandler(options, xhr, method, headers, error || virtualError);
331 } catch (e) {
332 DEBUG_BUILD && debug.warn('Error while extracting response event form XHR response', e);
333 }
334 });
335}
336
337/**
338 * Checks whether to capture given response as an event

Callers 1

setupFunction · 0.70

Calls 4

getClientFunction · 0.90
_xhrResponseHandlerFunction · 0.85
warnMethod · 0.65

Tested by

no test coverage detected