Skip to content

Commit df7ca14

Browse files
committed
Switch check for FirebaseError code to use includes
1 parent 39f4635 commit df7ca14

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ import * as util from './util';
4141
import { logger } from './logger';
4242
import { getState, clearState, setState, getDebugState } from './state';
4343
import { AppCheckTokenListener } from './public-types';
44-
import { Deferred, FirebaseError } from '@firebase/util';
44+
import { Deferred } from '@firebase/util';
4545
import { ReCaptchaEnterpriseProvider, ReCaptchaV3Provider } from './providers';
4646
import { AppCheckService } from './factory';
4747
import { ListenerType } from './types';
48-
import { AppCheckError } from './errors';
48+
import { AppCheckError, ERROR_FACTORY } from './errors';
4949

5050
const fakeRecaptchaToken = 'fake-recaptcha-token';
5151
const fakeRecaptchaAppCheckToken = {
@@ -396,11 +396,9 @@ describe('internal api', () => {
396396
const warnStub = stub(logger, 'warn');
397397
stub(client, 'exchangeToken').returns(
398398
Promise.reject(
399-
new FirebaseError(
400-
AppCheckError.FETCH_STATUS_ERROR,
401-
'test error msg',
402-
{ httpStatus: 503 }
403-
)
399+
ERROR_FACTORY.create(AppCheckError.FETCH_STATUS_ERROR, {
400+
httpStatus: 503
401+
})
404402
)
405403
);
406404

@@ -424,11 +422,9 @@ describe('internal api', () => {
424422
const warnStub = stub(logger, 'warn');
425423
stub(client, 'exchangeToken').returns(
426424
Promise.reject(
427-
new FirebaseError(
428-
AppCheckError.FETCH_STATUS_ERROR,
429-
'test error msg',
430-
{ httpStatus: 403 }
431-
)
425+
ERROR_FACTORY.create(AppCheckError.FETCH_STATUS_ERROR, {
426+
httpStatus: 403
427+
})
432428
)
433429
);
434430

packages/app-check/src/providers.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export class ReCaptchaV3Provider implements AppCheckProvider {
8080
this._heartbeatServiceProvider!
8181
);
8282
} catch (e) {
83-
if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) {
83+
console.log({ coder: (e as FirebaseError).code });
84+
if (
85+
(e as FirebaseError).code?.includes(AppCheckError.FETCH_STATUS_ERROR)
86+
) {
8487
this._throttleData = setBackoff(
8588
Number((e as FirebaseError).customData?.httpStatus),
8689
this._throttleData
@@ -167,7 +170,9 @@ export class ReCaptchaEnterpriseProvider implements AppCheckProvider {
167170
this._heartbeatServiceProvider!
168171
);
169172
} catch (e) {
170-
if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) {
173+
if (
174+
(e as FirebaseError).code?.includes(AppCheckError.FETCH_STATUS_ERROR)
175+
) {
171176
this._throttleData = setBackoff(
172177
Number((e as FirebaseError).customData?.httpStatus),
173178
this._throttleData

0 commit comments

Comments
 (0)