@@ -46,7 +46,7 @@ const _httpClientIntegration = ((options: Partial<HttpClientOptions> = {}) => {
46
46
47
47
return {
48
48
name : INTEGRATION_NAME ,
49
- setup ( client ) : void {
49
+ setup ( client : Client ) : void {
50
50
_wrapFetch ( client , _options ) ;
51
51
_wrapXHR ( client , _options ) ;
52
52
} ,
@@ -70,6 +70,7 @@ function _fetchResponseHandler(
70
70
requestInfo : RequestInfo ,
71
71
response : Response ,
72
72
requestInit ?: RequestInit ,
73
+ error ?: unknown ,
73
74
) : void {
74
75
if ( _shouldCaptureResponse ( options , response . status , response . url ) ) {
75
76
const request = _getRequest ( requestInfo , requestInit ) ;
@@ -89,9 +90,13 @@ function _fetchResponseHandler(
89
90
responseHeaders,
90
91
requestCookies,
91
92
responseCookies,
93
+ stacktrace : error instanceof Error ? error . stack : undefined ,
92
94
} ) ;
93
95
96
+ // withScope(scope => {
97
+ // scope.setFingerprint([request.url, request.method, response.status.toString()]);
94
98
captureEvent ( event ) ;
99
+ // });
95
100
}
96
101
}
97
102
@@ -127,6 +132,7 @@ function _xhrResponseHandler(
127
132
xhr : XMLHttpRequest ,
128
133
method : string ,
129
134
headers : Record < string , string > ,
135
+ error ?: unknown ,
130
136
) : void {
131
137
if ( _shouldCaptureResponse ( options , xhr . status , xhr . responseURL ) ) {
132
138
let requestHeaders , responseCookies , responseHeaders ;
@@ -159,6 +165,7 @@ function _xhrResponseHandler(
159
165
// Can't access request cookies from XHR
160
166
responseHeaders,
161
167
responseCookies,
168
+ stacktrace : error instanceof Error ? error . stack : undefined ,
162
169
} ) ;
163
170
164
171
captureEvent ( event ) ;
@@ -283,20 +290,24 @@ function _wrapFetch(client: Client, options: HttpClientOptions): void {
283
290
return ;
284
291
}
285
292
286
- addFetchInstrumentationHandler ( handlerData => {
287
- if ( getClient ( ) !== client ) {
288
- return ;
289
- }
293
+ addFetchInstrumentationHandler (
294
+ handlerData => {
295
+ if ( getClient ( ) !== client ) {
296
+ return ;
297
+ }
290
298
291
- const { response, args } = handlerData ;
292
- const [ requestInfo , requestInit ] = args as [ RequestInfo , RequestInit | undefined ] ;
299
+ const { response, args } = handlerData ;
300
+ const [ requestInfo , requestInit ] = args as [ RequestInfo , RequestInit | undefined ] ;
293
301
294
- if ( ! response ) {
295
- return ;
296
- }
302
+ if ( ! response ) {
303
+ return ;
304
+ }
297
305
298
- _fetchResponseHandler ( options , requestInfo , response as Response , requestInit ) ;
299
- } ) ;
306
+ _fetchResponseHandler ( options , requestInfo , response as Response , requestInit , handlerData . error ) ;
307
+ } ,
308
+ false ,
309
+ true ,
310
+ ) ;
300
311
}
301
312
302
313
/**
@@ -323,11 +334,11 @@ function _wrapXHR(client: Client, options: HttpClientOptions): void {
323
334
const { method, request_headers : headers } = sentryXhrData ;
324
335
325
336
try {
326
- _xhrResponseHandler ( options , xhr , method , headers ) ;
337
+ _xhrResponseHandler ( options , xhr , method , headers , handlerData . error ) ;
327
338
} catch ( e ) {
328
339
DEBUG_BUILD && logger . warn ( 'Error while extracting response event form XHR response' , e ) ;
329
340
}
330
- } ) ;
341
+ } , true ) ;
331
342
}
332
343
333
344
/**
@@ -358,7 +369,13 @@ function _createEvent(data: {
358
369
responseCookies ?: Record < string , string > ;
359
370
requestHeaders ?: Record < string , string > ;
360
371
requestCookies ?: Record < string , string > ;
372
+ stacktrace ?: string ;
361
373
} ) : SentryEvent {
374
+ const client = getClient ( ) ;
375
+ const virtualStackTrace = client && data . stacktrace ? data . stacktrace : undefined ;
376
+ // Remove the first frame from the stack as it's the HttpClient call
377
+ const stack = virtualStackTrace && client ? client . getOptions ( ) . stackParser ( virtualStackTrace , 0 , 1 ) : undefined ;
378
+
362
379
const message = `HTTP Client Error with status code: ${ data . status } ` ;
363
380
364
381
const event : SentryEvent = {
@@ -368,6 +385,7 @@ function _createEvent(data: {
368
385
{
369
386
type : 'Error' ,
370
387
value : message ,
388
+ stacktrace : stack ? { frames : stack } : undefined ,
371
389
} ,
372
390
] ,
373
391
} ,
0 commit comments