Skip to content

Commit 4e044e1

Browse files
committed
Address PR comments
1 parent bc2f60c commit 4e044e1

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

packages-exp/app-check-exp/src/internal-api.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('internal api', () => {
215215
});
216216
});
217217

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 () => {
219219
const appCheck = initializeAppCheck(app, {
220220
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY),
221221
isTokenAutoRefreshEnabled: true
@@ -227,7 +227,7 @@ describe('internal api', () => {
227227

228228
addTokenListener(
229229
appCheck as AppCheckService,
230-
ListenerType['2P'],
230+
ListenerType['3P'],
231231
listener1,
232232
errorFn1
233233
);

packages-exp/app-check-exp/src/internal-api.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,19 @@ function notifyTokenListeners(
284284

285285
for (const observer of observers) {
286286
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);
295292
} else {
293+
// If the token has no error field, always return the token.
296294
// 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);
302297
}
303298
} catch (e) {
304-
// If any handler fails, ignore and run next handler.
299+
// Errors in the listener function itself are always ignored.
305300
}
306301
}
307302
}

packages-exp/app-check-exp/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface AppCheckTokenObserver
4141
type: ListenerType;
4242
}
4343

44-
export enum ListenerType {
44+
export const enum ListenerType {
4545
'2P' = '2P',
4646
'3P' = '3P'
4747
}

packages-exp/app-check-exp/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"strict": true
5+
"strict": true,
6+
"preserveConstEnums": true
67
},
78
"exclude": ["dist/**/*"]
89
}

0 commit comments

Comments
 (0)