diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/GooglePlayBillingManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/GooglePlayBillingManager.java index 5649e6255..836ea55ec 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/GooglePlayBillingManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/GooglePlayBillingManager.java @@ -219,7 +219,9 @@ public class GooglePlayBillingManager implements SubscriptionPaymentProcessor { return executeTokenOperation(pub -> pub.purchases().subscriptions().cancel(packageName, purchase.getProductId(), purchaseToken)); - }); + }) + // If the subscription is not found, no need to do anything + .exceptionally(ExceptionUtils.exceptionallyHandler(SubscriptionException.NotFound.class, e -> null)); } @Override diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/GooglePlayBillingManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/GooglePlayBillingManagerTest.java index c47b4ea67..f8139b587 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/GooglePlayBillingManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/GooglePlayBillingManagerTest.java @@ -181,6 +181,16 @@ class GooglePlayBillingManagerTest { verify(cancel, times(wanted)).execute(); } + @Test + public void cancelMissingSubscription() throws IOException { + final HttpResponseException mockException = mock(HttpResponseException.class); + when(mockException.getStatusCode()).thenReturn(404); + when(subscriptionsv2Get.execute()).thenThrow(mockException); + assertThatNoException().isThrownBy(() -> + googlePlayBillingManager.cancelAllActiveSubscriptions(PURCHASE_TOKEN).join()); + verifyNoInteractions(cancel); + } + @Test public void getReceiptUnacknowledged() throws IOException { when(subscriptionsv2Get.execute()).thenReturn(new SubscriptionPurchaseV2()