diff --git a/packages/messaging/src/controllers/base-controller.ts b/packages/messaging/src/controllers/base-controller.ts index 44dcc1f4f63..8eb296eadda 100644 --- a/packages/messaging/src/controllers/base-controller.ts +++ b/packages/messaging/src/controllers/base-controller.ts @@ -238,7 +238,12 @@ export abstract class BaseController */ private async deleteTokenFromDB(token: string): Promise { const tokenDetails = await this.tokenDetailsModel.deleteToken(token); - await this.subscriptionManager.deleteToken(this.services, tokenDetails); + try { + await this.subscriptionManager.deleteToken(this.services, tokenDetails); + } catch (e) { + // A failed server-side delete does not need to break the app. + console.error(e); + } } // Visible for testing diff --git a/packages/messaging/test/controller-delete-token.test.ts b/packages/messaging/test/controller-delete-token.test.ts index 3cece088d43..5e1edc67973 100644 --- a/packages/messaging/test/controller-delete-token.test.ts +++ b/packages/messaging/test/controller-delete-token.test.ts @@ -210,7 +210,7 @@ describe('Firebase Messaging > *Controller.deleteToken()', () => { ); }); - it(`should handle error on deleteToken ${serviceClass.name}`, () => { + it(`should handle error on deleteToken ${serviceClass.name}`, async () => { const fakeSubscription: any = { endpoint: EXAMPLE_TOKEN_SAVE.endpoint, unsubscribe: async () => {} @@ -233,15 +233,11 @@ describe('Firebase Messaging > *Controller.deleteToken()', () => { throw new Error(errorMsg); }); + const consoleStub = stub(console, 'error'); + messagingService = new serviceClass(firebaseInternalServices); - return messagingService.deleteToken(EXAMPLE_TOKEN_SAVE.fcmToken).then( - () => { - throw new Error('Expected this to reject'); - }, - err => { - assert.equal(errorMsg, err.message); - } - ); + await messagingService.deleteToken(EXAMPLE_TOKEN_SAVE.fcmToken); + assert.equal(consoleStub.callCount, 1); }); it(`should delete with valid unsubscribe ${serviceClass.name}`, () => {