@@ -116,24 +116,36 @@ export async function getToken(
116
116
* Check token using the debug token, and return it directly.
117
117
*/
118
118
if ( isDebugMode ( ) ) {
119
- // Avoid making another call to the exchange endpoint if one is in flight.
120
- if ( ! state . exchangeTokenPromise ) {
121
- state . exchangeTokenPromise = exchangeToken (
122
- getExchangeDebugTokenRequest ( app , await getDebugToken ( ) ) ,
123
- appCheck . heartbeatServiceProvider
124
- ) . finally ( ( ) => {
125
- // Clear promise when settled - either resolved or rejected.
126
- state . exchangeTokenPromise = undefined ;
127
- } ) ;
128
- shouldCallListeners = true ;
119
+ try {
120
+ // Avoid making another call to the exchange endpoint if one is in flight.
121
+ if ( ! state . exchangeTokenPromise ) {
122
+ state . exchangeTokenPromise = exchangeToken (
123
+ getExchangeDebugTokenRequest ( app , await getDebugToken ( ) ) ,
124
+ appCheck . heartbeatServiceProvider
125
+ ) . finally ( ( ) => {
126
+ // Clear promise when settled - either resolved or rejected.
127
+ state . exchangeTokenPromise = undefined ;
128
+ } ) ;
129
+ shouldCallListeners = true ;
130
+ }
131
+ const tokenFromDebugExchange : AppCheckTokenInternal =
132
+ await state . exchangeTokenPromise ;
133
+ // Write debug token to indexedDB.
134
+ await writeTokenToStorage ( app , tokenFromDebugExchange ) ;
135
+ // Write debug token to state.
136
+ state . token = tokenFromDebugExchange ;
137
+ return { token : tokenFromDebugExchange . token } ;
138
+ } catch ( e ) {
139
+ if ( ( e as FirebaseError ) . code === `appCheck/${ AppCheckError . THROTTLED } ` ) {
140
+ // Warn if throttled, but do not treat it as an error.
141
+ logger . warn ( ( e as FirebaseError ) . message ) ;
142
+ } else {
143
+ // `getToken()` should never throw, but logging error text to console will aid debugging.
144
+ logger . error ( e ) ;
145
+ }
146
+ // Return dummy token and error
147
+ return makeDummyTokenResult ( e as FirebaseError ) ;
129
148
}
130
- const tokenFromDebugExchange : AppCheckTokenInternal =
131
- await state . exchangeTokenPromise ;
132
- // Write debug token to indexedDB.
133
- await writeTokenToStorage ( app , tokenFromDebugExchange ) ;
134
- // Write debug token to state.
135
- state . token = tokenFromDebugExchange ;
136
- return { token : tokenFromDebugExchange . token } ;
137
149
}
138
150
139
151
/**
0 commit comments