From a04e71d928c64f702ad25af74e2787b8d0eb805e Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Thu, 23 Jun 2022 11:31:48 +0200 Subject: [PATCH 1/2] fix(java): use body as error message --- .../main/java/com/algolia/utils/retry/RetryOutcome.java | 7 ------- .../main/java/com/algolia/utils/retry/RetryStrategy.java | 7 +++++-- 2 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryOutcome.java diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryOutcome.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryOutcome.java deleted file mode 100644 index f4c2c8b726..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryOutcome.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.algolia.utils.retry; - -public enum RetryOutcome { - SUCCESS, - RETRY, - FAILURE, -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryStrategy.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryStrategy.java index 2131e9d8e9..5e44050dde 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryStrategy.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryStrategy.java @@ -58,8 +58,11 @@ public Response intercept(Chain chain) throws IOException { response.close(); continue; } - // unkown state, fail - throw new AlgoliaApiException(response.message(), response.code()); + String message = response.message(); + if (response.body()) { + message = response.body().string(); + } + throw new AlgoliaApiException(message, response.code()); } catch (AlgoliaApiException e) { throw e; } catch (SocketTimeoutException e) { From a6ff9e21f5d5c6be18a4d46b11b3ca13b8e84130 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Thu, 23 Jun 2022 11:49:38 +0200 Subject: [PATCH 2/2] missing null check --- .../src/main/java/com/algolia/utils/retry/RetryStrategy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryStrategy.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryStrategy.java index 5e44050dde..d24b2710a6 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryStrategy.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/retry/RetryStrategy.java @@ -59,7 +59,7 @@ public Response intercept(Chain chain) throws IOException { continue; } String message = response.message(); - if (response.body()) { + if (response.body() != null) { message = response.body().string(); } throw new AlgoliaApiException(message, response.code());