@@ -847,12 +847,19 @@ class AsyncHttp2Call extends AsyncRequestCall {
847
847
...this . options . headers
848
848
} ) ;
849
849
850
+ // console.log("EMIT SESSION ERROR")
851
+ // this.http2ConfigImpl.http2SessionHandler.session.emit('error', "MOCK_SESSION_ERROR")
852
+
850
853
req . on ( 'response' , ( headers : IncomingHttp2Headers ) => {
851
854
this . handleHttp2Response ( headers , req ) ;
855
+
856
+ // console.log("EMIT SESSION ERROR")
857
+ // this.http2ConfigImpl.http2SessionHandler.session.emit('error', "MOCK_ERROR")
852
858
} ) ;
853
859
854
860
// Handle errors
855
861
req . on ( 'error' , ( err : any ) => {
862
+ console . log ( "GOT REQUEST ERROR" )
856
863
if ( req . aborted ) {
857
864
return ;
858
865
}
@@ -1315,9 +1322,16 @@ export class ExponentialBackoffPoller<T> extends EventEmitter {
1315
1322
export class Http2SessionHandler {
1316
1323
1317
1324
private http2Session : http2 . ClientHttp2Session
1325
+ protected promise : Promise < void >
1326
+ protected resolve : ( ) => void ;
1327
+ protected reject : ( _ : any ) => void ;
1318
1328
1319
1329
constructor ( url : string ) {
1320
- this . http2Session = this . createSession ( url )
1330
+ this . promise = new Promise ( ( resolve , reject ) => {
1331
+ this . resolve = resolve ;
1332
+ this . reject = reject ;
1333
+ this . http2Session = this . createSession ( url )
1334
+ } ) ;
1321
1335
}
1322
1336
1323
1337
public createSession ( url : string ) : http2 . ClientHttp2Session {
@@ -1330,23 +1344,37 @@ export class Http2SessionHandler {
1330
1344
const http2Session = http2 . connect ( url , opts )
1331
1345
1332
1346
http2Session . on ( 'goaway' , ( errorCode , _ , opaqueData ) => {
1333
- throw new FirebaseAppError (
1347
+ console . log ( "GOT SESSION GOAWAY EVENT" )
1348
+ this . reject ( new FirebaseAppError (
1334
1349
AppErrorCodes . NETWORK_ERROR ,
1335
1350
`Error while making requests: GOAWAY - ${ opaqueData . toString ( ) } , Error code: ${ errorCode } `
1336
- ) ;
1351
+ ) ) ;
1337
1352
} )
1338
1353
1339
1354
http2Session . on ( 'error' , ( error ) => {
1340
- throw new FirebaseAppError (
1355
+ console . log ( "GOT SESSION ERROR EVENT" )
1356
+ this . reject ( new FirebaseAppError (
1341
1357
AppErrorCodes . NETWORK_ERROR ,
1342
1358
`Error while making requests: ${ error } `
1343
- ) ;
1359
+ ) ) ;
1344
1360
} )
1361
+
1362
+ // Session close should be where we resolve the promise since we no longer need to listen for errors
1363
+ http2Session . on ( 'close' , ( ) => {
1364
+ console . log ( "GOT SESSION CLOSE EVENT" )
1365
+ this . resolve ( )
1366
+ } ) ;
1367
+
1345
1368
return http2Session
1346
1369
}
1347
1370
return this . http2Session
1348
1371
}
1349
1372
1373
+ // return the promise tracking events
1374
+ public invoke ( ) : Promise < void > {
1375
+ return this . promise
1376
+ }
1377
+
1350
1378
get session ( ) : http2 . ClientHttp2Session {
1351
1379
return this . http2Session
1352
1380
}
0 commit comments