diff --git a/.changeset/cyan-sheep-battle.md b/.changeset/cyan-sheep-battle.md new file mode 100644 index 00000000000..5741c2bc0b6 --- /dev/null +++ b/.changeset/cyan-sheep-battle.md @@ -0,0 +1,5 @@ +--- +'@firebase/app-check': patch +--- + +Fix logic to trigger app check throttling diff --git a/packages/app-check/src/internal-api.test.ts b/packages/app-check/src/internal-api.test.ts index 6a92e846f80..09b81f5ee24 100644 --- a/packages/app-check/src/internal-api.test.ts +++ b/packages/app-check/src/internal-api.test.ts @@ -41,11 +41,11 @@ import * as util from './util'; import { logger } from './logger'; import { getState, clearState, setState, getDebugState } from './state'; import { AppCheckTokenListener } from './public-types'; -import { Deferred, FirebaseError } from '@firebase/util'; +import { Deferred } from '@firebase/util'; import { ReCaptchaEnterpriseProvider, ReCaptchaV3Provider } from './providers'; import { AppCheckService } from './factory'; import { ListenerType } from './types'; -import { AppCheckError } from './errors'; +import { AppCheckError, ERROR_FACTORY } from './errors'; const fakeRecaptchaToken = 'fake-recaptcha-token'; const fakeRecaptchaAppCheckToken = { @@ -396,11 +396,9 @@ describe('internal api', () => { const warnStub = stub(logger, 'warn'); stub(client, 'exchangeToken').returns( Promise.reject( - new FirebaseError( - AppCheckError.FETCH_STATUS_ERROR, - 'test error msg', - { httpStatus: 503 } - ) + ERROR_FACTORY.create(AppCheckError.FETCH_STATUS_ERROR, { + httpStatus: 503 + }) ) ); @@ -424,11 +422,9 @@ describe('internal api', () => { const warnStub = stub(logger, 'warn'); stub(client, 'exchangeToken').returns( Promise.reject( - new FirebaseError( - AppCheckError.FETCH_STATUS_ERROR, - 'test error msg', - { httpStatus: 403 } - ) + ERROR_FACTORY.create(AppCheckError.FETCH_STATUS_ERROR, { + httpStatus: 403 + }) ) ); diff --git a/packages/app-check/src/providers.ts b/packages/app-check/src/providers.ts index cb07375dcf2..bf288259a82 100644 --- a/packages/app-check/src/providers.ts +++ b/packages/app-check/src/providers.ts @@ -80,7 +80,9 @@ export class ReCaptchaV3Provider implements AppCheckProvider { this._heartbeatServiceProvider! ); } catch (e) { - if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) { + if ( + (e as FirebaseError).code?.includes(AppCheckError.FETCH_STATUS_ERROR) + ) { this._throttleData = setBackoff( Number((e as FirebaseError).customData?.httpStatus), this._throttleData @@ -167,7 +169,9 @@ export class ReCaptchaEnterpriseProvider implements AppCheckProvider { this._heartbeatServiceProvider! ); } catch (e) { - if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) { + if ( + (e as FirebaseError).code?.includes(AppCheckError.FETCH_STATUS_ERROR) + ) { this._throttleData = setBackoff( Number((e as FirebaseError).customData?.httpStatus), this._throttleData