From 36045c116d5ecb18371ac4be40430a79004684ad Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Mon, 15 Jul 2024 23:23:52 -0700 Subject: [PATCH] Handle parsing empty or unexpected bodies without throwing a caused-by exception Resolves https://github.com/apple/app-store-server-library-java/issues/83 --- .../client/BaseAppStoreServerAPIClient.java | 8 +++++++- .../client/AppStoreServerAPIClientTest.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/apple/itunes/storekit/client/BaseAppStoreServerAPIClient.java b/src/main/java/com/apple/itunes/storekit/client/BaseAppStoreServerAPIClient.java index 29e65a5c..5d01b625 100644 --- a/src/main/java/com/apple/itunes/storekit/client/BaseAppStoreServerAPIClient.java +++ b/src/main/java/com/apple/itunes/storekit/client/BaseAppStoreServerAPIClient.java @@ -129,7 +129,13 @@ protected T makeHttpCall(String path, String method, Map {}, 400); + try { + client.getTransactionInfo("1234"); + } catch (APIException e) { + Assertions.assertEquals(400, e.getHttpStatusCode()); + Assertions.assertNull(e.getApiError()); + Assertions.assertNull(e.getRawApiError()); + Assertions.assertNull(e.getApiErrorMessage()); + Assertions.assertNull(e.getCause()); + return; + } + Assertions.fail(); + } + @Test public void testDecodingWithUnknownEnumValue() throws IOException, APIException { String body = TestingUtility.readFile("models/transactionHistoryResponseWithMalformedEnvironment.json");