From f588390bdb498ca9f63cb46e6234215b1028ca39 Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Fri, 26 Jun 2026 11:07:49 -0500 Subject: [PATCH] Handle ACCOUNT_NOT_FOUND errors in AppleAppStoreClient --- .../subscriptions/AppleAppStoreClient.java | 4 ++-- .../subscriptions/AppleAppStoreClientTest.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/AppleAppStoreClient.java b/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/AppleAppStoreClient.java index 9f5bd11e8..66030ab02 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/AppleAppStoreClient.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/AppleAppStoreClient.java @@ -133,7 +133,7 @@ public class AppleAppStoreClient { final APIError apiError = e.getApiError(); Metrics.counter(GET_SUBSCRIPTION_ERROR_COUNTER_NAME, errorTags.and("reason", apiError != null ? apiError.name() : "http_" + e.getHttpStatusCode())).increment(); throw switch (e.getApiError()) { - case TRANSACTION_ID_NOT_FOUND, ORIGINAL_TRANSACTION_ID_NOT_FOUND -> new SubscriptionNotFoundException(); + case TRANSACTION_ID_NOT_FOUND, ORIGINAL_TRANSACTION_ID_NOT_FOUND, ACCOUNT_NOT_FOUND -> new SubscriptionNotFoundException(); case RATE_LIMIT_EXCEEDED -> new RateLimitExceededException(null); case INVALID_ORIGINAL_TRANSACTION_ID -> new SubscriptionInvalidArgumentsException(e.getApiErrorMessage()); case null, default -> throw e; @@ -183,7 +183,7 @@ public class AppleAppStoreClient { private static boolean shouldRetry(Throwable e) { return e instanceof APIException apiException && switch (apiException.getApiError()) { - case ORIGINAL_TRANSACTION_ID_NOT_FOUND_RETRYABLE, GENERAL_INTERNAL_RETRYABLE, APP_NOT_FOUND_RETRYABLE -> true; + case ORIGINAL_TRANSACTION_ID_NOT_FOUND_RETRYABLE, GENERAL_INTERNAL_RETRYABLE, APP_NOT_FOUND_RETRYABLE, ACCOUNT_NOT_FOUND_RETRYABLE -> true; case null, default -> false; }; } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/AppleAppStoreClientTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/AppleAppStoreClientTest.java index 83e60395f..87171423b 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/AppleAppStoreClientTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/AppleAppStoreClientTest.java @@ -6,6 +6,7 @@ package org.whispersystems.textsecuregcm.subscriptions; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; @@ -63,6 +64,19 @@ class AppleAppStoreClientTest { verifyNoInteractions(sandboxClient); } + @ParameterizedTest + @EnumSource(mode = EnumSource.Mode.INCLUDE, names = {"TRANSACTION_ID_NOT_FOUND", "ORIGINAL_TRANSACTION_ID_NOT_FOUND", "ACCOUNT_NOT_FOUND"}) + public void notFound(APIError error) throws APIException, IOException { + when(productionClient.getAllSubscriptionStatuses(ORIGINAL_TX_ID, new Status[]{})) + .thenThrow(new APIException(404, error, "test")); + when(sandboxClient.getAllSubscriptionStatuses(ORIGINAL_TX_ID, new Status[]{})) + .thenThrow(new APIException(404, error, "test")); + + assertThatExceptionOfType(SubscriptionNotFoundException.class) + .isThrownBy(() -> apiWrapper.getAllSubscriptions(ORIGINAL_TX_ID, Tags.empty())); + + } + @Test public void fallbackOnNoTransactionFound() throws APIException, IOException, SubscriptionInvalidArgumentsException, SubscriptionNotFoundException, RateLimitExceededException {