@@ -32,7 +32,7 @@ import { User } from '../auth/user';
3232import { debugAssert , hardAssert } from '../util/assert' ;
3333import { AsyncQueue } from '../util/async_queue' ;
3434import { Code , FirestoreError } from '../util/error' ;
35- import { logDebug } from '../util/log' ;
35+ import { logDebug , logWarn } from '../util/log' ;
3636import { Deferred } from '../util/promise' ;
3737
3838// TODO(mikelehen): This should be split into multiple files and probably
@@ -527,12 +527,28 @@ export class FirebaseAppCheckTokenProvider
527527 const onTokenChanged : (
528528 tokenResult : AppCheckTokenResult
529529 ) => Promise < void > = tokenResult => {
530- if ( tokenResult . error != null ) {
531- logDebug (
530+ if ( tokenResult . error ) {
531+ const code = getCode ( tokenResult . error ) ;
532+ logWarn (
532533 'FirebaseAppCheckTokenProvider' ,
533- `Error getting App Check token; using placeholder token instead. Error : ${ tokenResult . error . message } `
534+ `Error getting App Check token (code= ${ code } ) : ${ tokenResult . error . message } `
534535 ) ;
536+
537+ // Ignore errors due to the App Check provider throttling requests to
538+ // the provider's servers. Treat these errors as if nothing happened
539+ // because App Check will get the provider to try again after throttling
540+ // unblock it, at which point we will get a shiny, new, valid token.
541+ if ( isAppCheckThrottleCode ( code ) ) {
542+ logWarn (
543+ 'FirebaseAppCheckTokenProvider' ,
544+ 'ignoring failed App Check token retrieval since it is throttled ' +
545+ 'and App Check will try again later. (code=${code})'
546+ ) ;
547+ return Promise . resolve ( ) ;
548+ }
549+ logWarn ( 'FirebaseAppCheckTokenProvider' , 'using placeholder token' ) ;
535550 }
551+
536552 const tokenUpdated = tokenResult . token !== this . latestAppCheckToken ;
537553 this . latestAppCheckToken = tokenResult . token ;
538554 logDebug (
@@ -718,3 +734,15 @@ export function makeAuthCredentialsProvider(
718734 ) ;
719735 }
720736}
737+
738+ function getCode ( error : Error ) : string | undefined {
739+ return 'code' in error && typeof error . code === 'string'
740+ ? error . code
741+ : undefined ;
742+ }
743+
744+ type AppCheckThrottleCode = 'appCheck/initial-throttle' | 'appCheck/throttled' ;
745+
746+ function isAppCheckThrottleCode ( code : unknown ) : code is AppCheckThrottleCode {
747+ return code === 'appCheck/initial-throttle' || code === 'appCheck/throttled' ;
748+ }
0 commit comments