File tree Expand file tree Collapse file tree 4 files changed +14
-18
lines changed
packages-exp/app-check-exp Expand file tree Collapse file tree 4 files changed +14
-18
lines changed Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ describe('internal api', () => {
215
215
} ) ;
216
216
} ) ;
217
217
218
- it ( 'calls optional error handler if there is an error getting a token' , async ( ) => {
218
+ it ( 'calls 3P error handler if there is an error getting a token' , async ( ) => {
219
219
const appCheck = initializeAppCheck ( app , {
220
220
provider : new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
221
221
isTokenAutoRefreshEnabled : true
@@ -227,7 +227,7 @@ describe('internal api', () => {
227
227
228
228
addTokenListener (
229
229
appCheck as AppCheckService ,
230
- ListenerType [ '2P ' ] ,
230
+ ListenerType [ '3P ' ] ,
231
231
listener1 ,
232
232
errorFn1
233
233
) ;
Original file line number Diff line number Diff line change @@ -284,24 +284,19 @@ function notifyTokenListeners(
284
284
285
285
for ( const observer of observers ) {
286
286
try {
287
- if ( observer . error ) {
288
- // If this listener has an error handler, handle errors differently
289
- // from successes.
290
- if ( token . error ) {
291
- observer . error ( token . error ) ;
292
- } else {
293
- observer . next ( token ) ;
294
- }
287
+ if ( observer . type === ListenerType [ '3P' ] && token . error != null ) {
288
+ // If this listener was added by a 3P call, send any token error to
289
+ // the supplied error handler. A 3P observer always has an error
290
+ // handler.
291
+ observer . error ! ( token . error ) ;
295
292
} else {
293
+ // If the token has no error field, always return the token.
296
294
// If this is a 2P listener, return the token, whether or not it
297
- // has an error field. If it is a 3P listener with no error handler,
298
- // ignore the error.
299
- if ( observer . type === ListenerType [ '2P' ] ) {
300
- observer . next ( token ) ;
301
- }
295
+ // has an error field.
296
+ observer . next ( token ) ;
302
297
}
303
298
} catch ( e ) {
304
- // If any handler fails, ignore and run next handler .
299
+ // Errors in the listener function itself are always ignored .
305
300
}
306
301
}
307
302
}
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export interface AppCheckTokenObserver
41
41
type : ListenerType ;
42
42
}
43
43
44
- export enum ListenerType {
44
+ export const enum ListenerType {
45
45
'2P' = '2P' ,
46
46
'3P' = '3P'
47
47
}
Original file line number Diff line number Diff line change 2
2
"extends" : " ../../config/tsconfig.base.json" ,
3
3
"compilerOptions" : {
4
4
"outDir" : " dist" ,
5
- "strict" : true
5
+ "strict" : true ,
6
+ "preserveConstEnums" : true
6
7
},
7
8
"exclude" : [" dist/**/*" ]
8
9
}
You can’t perform that action at this time.
0 commit comments