Skip to content

Commit

Permalink
Suppress server errors in deleteToken request (#2428)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmermerkaya authored Dec 10, 2019
1 parent 5a880c6 commit ff8f854
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
7 changes: 6 additions & 1 deletion packages/messaging/src/controllers/base-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ export abstract class BaseController
*/
private async deleteTokenFromDB(token: string): Promise<void> {
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
Expand Down
14 changes: 5 additions & 9 deletions packages/messaging/test/controller-delete-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {}
Expand All @@ -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}`, () => {
Expand Down

0 comments on commit ff8f854

Please sign in to comment.