@@ -80,47 +80,42 @@ function instrumentFetch(onFetchResolved?: (response: Response) => void, skipNat
80
80
if ( onFetchResolved ) {
81
81
onFetchResolved ( response ) ;
82
82
} else {
83
- const finishedHandlerData : HandlerDataFetch = {
83
+ triggerHandlers ( 'fetch' , {
84
84
...handlerData ,
85
85
endTimestamp : timestampInSeconds ( ) * 1000 ,
86
86
response,
87
- } ;
88
- triggerHandlers ( 'fetch' , finishedHandlerData ) ;
87
+ } ) ;
89
88
}
90
89
91
90
return response ;
92
91
} ,
93
92
( error : Error ) => {
94
- if ( ! onFetchResolved ) {
95
- const erroredHandlerData : HandlerDataFetch = {
96
- ...handlerData ,
97
- endTimestamp : timestampInSeconds ( ) * 1000 ,
98
- error,
99
- } ;
100
-
101
- triggerHandlers ( 'fetch' , erroredHandlerData ) ;
102
-
103
- if ( isError ( error ) && error . stack === undefined ) {
104
- // NOTE: If you are a Sentry user, and you are seeing this stack frame,
105
- // it means the error, that was caused by your fetch call did not
106
- // have a stack trace, so the SDK backfilled the stack trace so
107
- // you can see which fetch call failed.
108
- error . stack = virtualStackTrace ;
109
- addNonEnumerableProperty ( error , 'framesToPop' , 1 ) ;
110
- }
93
+ triggerHandlers ( 'fetch' , {
94
+ ...handlerData ,
95
+ endTimestamp : timestampInSeconds ( ) * 1000 ,
96
+ error,
97
+ } ) ;
111
98
99
+ if ( isError ( error ) && error . stack === undefined ) {
112
100
// NOTE: If you are a Sentry user, and you are seeing this stack frame,
113
- // it means the sentry.javascript SDK caught an error invoking your application code.
114
- // This is expected behavior and NOT indicative of a bug with sentry.javascript.
115
- throw error ;
101
+ // it means the error, that was caused by your fetch call did not
102
+ // have a stack trace, so the SDK backfilled the stack trace so
103
+ // you can see which fetch call failed.
104
+ error . stack = virtualStackTrace ;
105
+ addNonEnumerableProperty ( error , 'framesToPop' , 1 ) ;
116
106
}
107
+
108
+ // NOTE: If you are a Sentry user, and you are seeing this stack frame,
109
+ // it means the sentry.javascript SDK caught an error invoking your application code.
110
+ // This is expected behavior and NOT indicative of a bug with sentry.javascript.
111
+ throw error ;
117
112
} ,
118
113
) ;
119
114
} ;
120
115
} ) ;
121
116
}
122
117
123
- function resolveResponse ( res : Response | undefined , onFinishedResolving : ( ) => void ) : void {
118
+ async function resolveResponse ( res : Response | undefined , onFinishedResolving : ( ) => void ) : Promise < void > {
124
119
if ( res && res . body ) {
125
120
const responseReader = res . body . getReader ( ) ;
126
121
@@ -146,25 +141,21 @@ function resolveResponse(res: Response | undefined, onFinishedResolving: () => v
146
141
}
147
142
}
148
143
149
- responseReader
144
+ return responseReader
150
145
. read ( )
151
146
. then ( consumeChunks )
152
- . then ( ( ) => {
153
- onFinishedResolving ( ) ;
154
- } )
155
- . catch ( ( ) => {
156
- // noop
157
- } ) ;
147
+ . then ( onFinishedResolving )
148
+ . catch ( ( ) => undefined ) ;
158
149
}
159
150
}
160
151
161
152
async function streamHandler ( response : Response ) : Promise < void > {
162
153
// clone response for awaiting stream
163
- let clonedResponseForResolving : Response | undefined ;
154
+ let clonedResponseForResolving : Response ;
164
155
try {
165
156
clonedResponseForResolving = response . clone ( ) ;
166
- } catch ( e ) {
167
- // noop
157
+ } catch {
158
+ return ;
168
159
}
169
160
170
161
await resolveResponse ( clonedResponseForResolving , ( ) => {
0 commit comments