* Wraps XMLHttpRequest to capture request and response data
(client: Client, options: HttpClientOptions)
| 305 | * Wraps XMLHttpRequest to capture request and response data |
| 306 | */ |
| 307 | function _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 |
no test coverage detected