From df7ca145178f29f590ed1fe40647b073a00e7e87 Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Fri, 15 Jul 2022 15:16:18 -0400 Subject: [PATCH 1/4] Switch check for FirebaseError code to use includes --- packages/app-check/src/internal-api.test.ts | 20 ++++++++------------ packages/app-check/src/providers.ts | 9 +++++++-- 2 files changed, 15 insertions(+), 14 deletions(-) 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..5b46ede9d35 100644 --- a/packages/app-check/src/providers.ts +++ b/packages/app-check/src/providers.ts @@ -80,7 +80,10 @@ export class ReCaptchaV3Provider implements AppCheckProvider { this._heartbeatServiceProvider! ); } catch (e) { - if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) { + console.log({ coder: (e as FirebaseError).code }); + if ( + (e as FirebaseError).code?.includes(AppCheckError.FETCH_STATUS_ERROR) + ) { this._throttleData = setBackoff( Number((e as FirebaseError).customData?.httpStatus), this._throttleData @@ -167,7 +170,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 From 9fd1f38c7399230073b6e61838b324ff27e59c3d Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Fri, 15 Jul 2022 15:32:18 -0400 Subject: [PATCH 2/4] Add changeset --- .changeset/cyan-sheep-battle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cyan-sheep-battle.md diff --git a/.changeset/cyan-sheep-battle.md b/.changeset/cyan-sheep-battle.md new file mode 100644 index 00000000000..4260494b847 --- /dev/null +++ b/.changeset/cyan-sheep-battle.md @@ -0,0 +1,5 @@ +--- +'@firebase/app-check': minor +--- + +Fix logic to trigger app check throttling From 8ab6d5e786ec2b2a218bfff43adc67b9318b19a8 Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Fri, 15 Jul 2022 16:52:43 -0400 Subject: [PATCH 3/4] Update changeset to a patch --- .changeset/cyan-sheep-battle.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/cyan-sheep-battle.md b/.changeset/cyan-sheep-battle.md index 4260494b847..5741c2bc0b6 100644 --- a/.changeset/cyan-sheep-battle.md +++ b/.changeset/cyan-sheep-battle.md @@ -1,5 +1,5 @@ --- -'@firebase/app-check': minor +'@firebase/app-check': patch --- Fix logic to trigger app check throttling From 0efea24420e39fedb0d164232607b2146c17efb2 Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Mon, 18 Jul 2022 15:02:01 -0400 Subject: [PATCH 4/4] Remove debugging console.log --- packages/app-check/src/providers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/app-check/src/providers.ts b/packages/app-check/src/providers.ts index 5b46ede9d35..bf288259a82 100644 --- a/packages/app-check/src/providers.ts +++ b/packages/app-check/src/providers.ts @@ -80,7 +80,6 @@ export class ReCaptchaV3Provider implements AppCheckProvider { this._heartbeatServiceProvider! ); } catch (e) { - console.log({ coder: (e as FirebaseError).code }); if ( (e as FirebaseError).code?.includes(AppCheckError.FETCH_STATUS_ERROR) ) {