@@ -70,7 +70,7 @@ function _fetchResponseHandler(
7070 requestInfo : RequestInfo ,
7171 response : Response ,
7272 requestInit ?: RequestInit ,
73- stack ?: string ,
73+ error ?: unknown ,
7474) : void {
7575 if ( _shouldCaptureResponse ( options , response . status , response . url ) ) {
7676 const request = _getRequest ( requestInfo , requestInit ) ;
@@ -90,7 +90,7 @@ function _fetchResponseHandler(
9090 responseHeaders,
9191 requestCookies,
9292 responseCookies,
93- stacktrace : stack ,
93+ error ,
9494 } ) ;
9595
9696 captureEvent ( event ) ;
@@ -129,7 +129,7 @@ function _xhrResponseHandler(
129129 xhr : XMLHttpRequest ,
130130 method : string ,
131131 headers : Record < string , string > ,
132- stack ?: string ,
132+ error ?: unknown ,
133133) : void {
134134 if ( _shouldCaptureResponse ( options , xhr . status , xhr . responseURL ) ) {
135135 let requestHeaders , responseCookies , responseHeaders ;
@@ -162,7 +162,7 @@ function _xhrResponseHandler(
162162 // Can't access request cookies from XHR
163163 responseHeaders,
164164 responseCookies,
165- stacktrace : stack ,
165+ error ,
166166 } ) ;
167167
168168 captureEvent ( event ) ;
@@ -292,14 +292,14 @@ function _wrapFetch(client: Client, options: HttpClientOptions): void {
292292 return ;
293293 }
294294
295- const { response, args } = handlerData ;
295+ const { response, args, error , virtualError } = handlerData ;
296296 const [ requestInfo , requestInit ] = args as [ RequestInfo , RequestInit | undefined ] ;
297297
298298 if ( ! response ) {
299299 return ;
300300 }
301301
302- _fetchResponseHandler ( options , requestInfo , response as Response , requestInit , handlerData . stack ) ;
302+ _fetchResponseHandler ( options , requestInfo , response as Response , requestInit , error || virtualError ) ;
303303 } , false ) ;
304304}
305305
@@ -316,6 +316,8 @@ function _wrapXHR(client: Client, options: HttpClientOptions): void {
316316 return ;
317317 }
318318
319+ const { error, virtualError } = handlerData ;
320+
319321 const xhr = handlerData . xhr as SentryWrappedXMLHttpRequest & XMLHttpRequest ;
320322
321323 const sentryXhrData = xhr [ SENTRY_XHR_DATA_KEY ] ;
@@ -327,7 +329,7 @@ function _wrapXHR(client: Client, options: HttpClientOptions): void {
327329 const { method, request_headers : headers } = sentryXhrData ;
328330
329331 try {
330- _xhrResponseHandler ( options , xhr , method , headers , handlerData . stack ) ;
332+ _xhrResponseHandler ( options , xhr , method , headers , error || virtualError ) ;
331333 } catch ( e ) {
332334 DEBUG_BUILD && logger . warn ( 'Error while extracting response event form XHR response' , e ) ;
333335 }
@@ -362,13 +364,12 @@ function _createEvent(data: {
362364 responseCookies ?: Record < string , string > ;
363365 requestHeaders ?: Record < string , string > ;
364366 requestCookies ?: Record < string , string > ;
365- stacktrace ?: string ;
367+ error ?: unknown ;
366368} ) : SentryEvent {
367369 const client = getClient ( ) ;
368- const virtualStackTrace = client && data . stacktrace ? data . stacktrace : undefined ;
370+ const virtualStackTrace = client && data . error && data . error instanceof Error ? data . error . stack : undefined ;
369371 // Remove the first frame from the stack as it's the HttpClient call
370372 const stack = virtualStackTrace && client ? client . getOptions ( ) . stackParser ( virtualStackTrace , 0 , 1 ) : undefined ;
371-
372373 const message = `HTTP Client Error with status code: ${ data . status } ` ;
373374
374375 const event : SentryEvent = {
0 commit comments