@@ -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
@@ -151,6 +156,9 @@ function _xhrResponseHandler(
151
156
requestHeaders = headers ;
152
157
}
153
158
159
+ const virtualError = new Error ( ) ;
160
+ const virtualStacktrace = virtualError . stack ;
161
+
154
162
const event = _createEvent ( {
155
163
url : xhr . responseURL ,
156
164
method,
@@ -159,6 +167,7 @@ function _xhrResponseHandler(
159
167
// Can't access request cookies from XHR
160
168
responseHeaders,
161
169
responseCookies,
170
+ stacktrace : virtualStacktrace ,
162
171
} ) ;
163
172
164
173
captureEvent ( event ) ;
@@ -283,20 +292,24 @@ function _wrapFetch(client: Client, options: HttpClientOptions): void {
283
292
return ;
284
293
}
285
294
286
- addFetchInstrumentationHandler ( handlerData => {
287
- if ( getClient ( ) !== client ) {
288
- return ;
289
- }
295
+ addFetchInstrumentationHandler (
296
+ handlerData => {
297
+ if ( getClient ( ) !== client ) {
298
+ return ;
299
+ }
290
300
291
- const { response, args } = handlerData ;
292
- const [ requestInfo , requestInit ] = args as [ RequestInfo , RequestInit | undefined ] ;
301
+ const { response, args } = handlerData ;
302
+ const [ requestInfo , requestInit ] = args as [ RequestInfo , RequestInit | undefined ] ;
293
303
294
- if ( ! response ) {
295
- return ;
296
- }
304
+ if ( ! response ) {
305
+ return ;
306
+ }
297
307
298
- _fetchResponseHandler ( options , requestInfo , response as Response , requestInit ) ;
299
- } ) ;
308
+ _fetchResponseHandler ( options , requestInfo , response as Response , requestInit , handlerData . error ) ;
309
+ } ,
310
+ false ,
311
+ true ,
312
+ ) ;
300
313
}
301
314
302
315
/**
@@ -327,7 +340,7 @@ function _wrapXHR(client: Client, options: HttpClientOptions): void {
327
340
} catch ( e ) {
328
341
DEBUG_BUILD && logger . warn ( 'Error while extracting response event form XHR response' , e ) ;
329
342
}
330
- } ) ;
343
+ } , true ) ;
331
344
}
332
345
333
346
/**
@@ -358,7 +371,15 @@ function _createEvent(data: {
358
371
responseCookies ?: Record < string , string > ;
359
372
requestHeaders ?: Record < string , string > ;
360
373
requestCookies ?: Record < string , string > ;
374
+ stacktrace ?: string ;
361
375
} ) : SentryEvent {
376
+ const client = getClient ( ) ;
377
+ const virtualStackTrace = client && data . stacktrace ? data . stacktrace : undefined ;
378
+ const stack = virtualStackTrace && client ? client . getOptions ( ) . stackParser ( virtualStackTrace ) : undefined ;
379
+
380
+ // Remove the first frame from the stack as it's the HttpClient call
381
+ const nonSentryStack = stack && stack . length ? stack . slice ( 1 ) : undefined ;
382
+
362
383
const message = `HTTP Client Error with status code: ${ data . status } ` ;
363
384
364
385
const event : SentryEvent = {
@@ -368,6 +389,7 @@ function _createEvent(data: {
368
389
{
369
390
type : 'Error' ,
370
391
value : message ,
392
+ stacktrace : stack ? { frames : nonSentryStack } : undefined ,
371
393
} ,
372
394
] ,
373
395
} ,
0 commit comments