@@ -209,33 +209,48 @@ export class Messaging {
209
209
// const http2SessionHandler = this.useLegacyTransport ? undefined : new Http2SessionHandler(`https://${FCM_SEND_HOST}`)
210
210
const http2SessionHandler = this . useLegacyTransport ? undefined : new Http2SessionHandler ( `https://localhost:3001` ) ;
211
211
212
+
212
213
return this . getUrlPath ( )
213
214
. then ( ( urlPath ) => {
214
- // Try listening for errors here?
215
+ // Try listening for errors here?
215
216
if ( http2SessionHandler ) {
216
- http2SessionHandler . invoke ( ) . catch ( ( error ) => {
217
- console . log ( "ERROR TO BE PASSED TO USER:" )
218
- console . log ( error )
219
-
220
- // Throwing here does nothing since it's still not in the promise that's returned?
221
- throw error
217
+ let batchResponsePromise : Promise < PromiseSettledResult < SendResponse > [ ] >
218
+ return new Promise ( ( resolve : ( result : PromiseSettledResult < SendResponse > [ ] ) => void , reject ) => {
219
+ http2SessionHandler . invoke ( ) . catch ( ( error ) => {
220
+ console . log ( "ERROR TO BE PASSED TO USER:" )
221
+ console . log ( error )
222
+ reject ( { error, batchResponsePromise} )
223
+ } )
224
+
225
+
226
+ const requests : Promise < SendResponse > [ ] = copy . map ( async ( message ) => {
227
+ validateMessage ( message ) ;
228
+ const request : { message : Message ; validate_only ?: boolean } = { message } ;
229
+ if ( dryRun ) {
230
+ request . validate_only = true ;
231
+ }
232
+ return this . messagingRequestHandler . invokeHttp2RequestHandlerForSendResponse (
233
+ FCM_SEND_HOST , urlPath , request , http2SessionHandler ) ;
234
+ } ) ;
235
+ batchResponsePromise = Promise . allSettled ( requests )
236
+ batchResponsePromise . then ( resolve ) . catch ( ( error ) => {
237
+ reject ( { error, batchResponsePromise} )
238
+ } )
222
239
} )
223
240
}
224
241
242
+ //
225
243
const requests : Promise < SendResponse > [ ] = copy . map ( async ( message ) => {
226
244
validateMessage ( message ) ;
227
245
const request : { message : Message ; validate_only ?: boolean } = { message } ;
228
246
if ( dryRun ) {
229
247
request . validate_only = true ;
230
248
}
231
-
232
- if ( http2SessionHandler ) {
233
- return this . messagingRequestHandler . invokeHttp2RequestHandlerForSendResponse (
234
- FCM_SEND_HOST , urlPath , request , http2SessionHandler ) ;
235
- }
236
249
return this . messagingRequestHandler . invokeHttpRequestHandlerForSendResponse ( FCM_SEND_HOST , urlPath , request ) ;
237
250
} ) ;
238
251
return Promise . allSettled ( requests ) ;
252
+ //
253
+
239
254
} )
240
255
. then ( ( results ) => {
241
256
const responses : SendResponse [ ] = [ ] ;
@@ -253,11 +268,6 @@ export class Messaging {
253
268
failureCount : responses . length - successCount ,
254
269
} ;
255
270
} )
256
- . finally ( ( ) => {
257
- if ( http2SessionHandler ) {
258
- http2SessionHandler . close ( )
259
- }
260
- } ) ;
261
271
}
262
272
263
273
/**
0 commit comments