@@ -80,47 +80,42 @@ function instrumentFetch(onFetchResolved?: (response: Response) => void, skipNat
8080 if ( onFetchResolved ) {
8181 onFetchResolved ( response ) ;
8282 } else {
83- const finishedHandlerData : HandlerDataFetch = {
83+ triggerHandlers ( 'fetch' , {
8484 ...handlerData ,
8585 endTimestamp : timestampInSeconds ( ) * 1000 ,
8686 response,
87- } ;
88- triggerHandlers ( 'fetch' , finishedHandlerData ) ;
87+ } ) ;
8988 }
9089
9190 return response ;
9291 } ,
9392 ( 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+ } ) ;
11198
99+ if ( isError ( error ) && error . stack === undefined ) {
112100 // 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 ) ;
116106 }
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 ;
117112 } ,
118113 ) ;
119114 } ;
120115 } ) ;
121116}
122117
123- function resolveResponse ( res : Response | undefined , onFinishedResolving : ( ) => void ) : void {
118+ async function resolveResponse ( res : Response | undefined , onFinishedResolving : ( ) => void ) : Promise < void > {
124119 if ( res && res . body ) {
125120 const responseReader = res . body . getReader ( ) ;
126121
@@ -146,25 +141,21 @@ function resolveResponse(res: Response | undefined, onFinishedResolving: () => v
146141 }
147142 }
148143
149- responseReader
144+ return responseReader
150145 . read ( )
151146 . then ( consumeChunks )
152- . then ( ( ) => {
153- onFinishedResolving ( ) ;
154- } )
155- . catch ( ( ) => {
156- // noop
157- } ) ;
147+ . then ( onFinishedResolving )
148+ . catch ( ( ) => undefined ) ;
158149 }
159150}
160151
161152async function streamHandler ( response : Response ) : Promise < void > {
162153 // clone response for awaiting stream
163- let clonedResponseForResolving : Response | undefined ;
154+ let clonedResponseForResolving : Response ;
164155 try {
165156 clonedResponseForResolving = response . clone ( ) ;
166- } catch ( e ) {
167- // noop
157+ } catch {
158+ return ;
168159 }
169160
170161 await resolveResponse ( clonedResponseForResolving , ( ) => {
0 commit comments