From af1d32204b31369cb27df10d150db9cca0f36ab5 Mon Sep 17 00:00:00 2001 From: Steve Ban <48812298+julius-ban@users.noreply.github.com> Date: Thu, 30 Apr 2026 15:59:04 +0900 Subject: [PATCH 1/3] fix: preserve exception cause in RestClient error handling Wrapping original exceptions as causes in RuntimeException constructors across execRequest() and execPost() to retain full stack traces for debugging. --- src/main/java/co/elastic/support/rest/RestClient.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/co/elastic/support/rest/RestClient.java b/src/main/java/co/elastic/support/rest/RestClient.java index 85feb33b..8c64c8fb 100644 --- a/src/main/java/co/elastic/support/rest/RestClient.java +++ b/src/main/java/co/elastic/support/rest/RestClient.java @@ -86,10 +86,10 @@ private HttpResponse execRequest(HttpRequestBase httpRequest) { return client.execute(httpHost, httpRequest, httpContext); } catch (HttpHostConnectException e) { logger.error("Host connection error.", e); - throw new RuntimeException("Host connection"); + throw new RuntimeException("Host connection failed", e); } catch (Exception e) { logger.error("Unexpected Execution Error", e); - throw new RuntimeException(e.getMessage()); + throw new RuntimeException("Unexpected error during HTTP execution", e); } } @@ -104,7 +104,7 @@ public HttpResponse execPost(String uri, String payload) { return execRequest(httpPost); } catch (UnsupportedEncodingException e) { logger.error(Constants.CONSOLE, "Error with json body.", e); - throw new RuntimeException("Could not complete post request."); + throw new RuntimeException("Could not complete post request.", e); } } @@ -229,4 +229,4 @@ public static RestClient getClient( throw new RuntimeException("Error establishing http connection for: " + host, e); } } -} \ No newline at end of file +} From 7cba0dd970e7c0dfcbaf38438d3cd2c64392a36a Mon Sep 17 00:00:00 2001 From: Steve Ban <48812298+julius-ban@users.noreply.github.com> Date: Thu, 30 Apr 2026 15:59:48 +0900 Subject: [PATCH 2/3] fix: preserve exception cause in RestClient error handling Wrapping original exceptions as causes in RuntimeException constructors across execRequest() and execPost() to retain full stack traces for debugging. --- .../support/rest/TestRestExecCalls.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/co/elastic/support/rest/TestRestExecCalls.java b/src/test/java/co/elastic/support/rest/TestRestExecCalls.java index 1c7a545b..2ff79576 100644 --- a/src/test/java/co/elastic/support/rest/TestRestExecCalls.java +++ b/src/test/java/co/elastic/support/rest/TestRestExecCalls.java @@ -31,6 +31,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -189,6 +191,31 @@ public void testAuthFailure() { assertTrue(fileExistsWithText(targetFilename, "autherror_response_body")); } + @Test + public void testConnectionRefusedPreservesCause() { + RestClient unreachableClient = RestClient.getClient( + "localhost", + 19999, + "http", + "elastic", + "elastic", + "", + 0, + "", + "", + "", + "", + true, + Collections.emptyMap(), + 1000, + 1000, + 1000); + + RuntimeException ex = assertThrows(RuntimeException.class, + () -> unreachableClient.execGet("/")); + assertNotNull(ex.getCause(), "RuntimeException must preserve original cause"); + } + private boolean fileExistsWithText(String filename, String compare) { try { String fileContents = FileUtils.readFileToString(new File(filename), "UTF8"); From a1b3246afbb3bf6cd1f18789a4b343c283d5456d Mon Sep 17 00:00:00 2001 From: Steve Ban <48812298+julius-ban@users.noreply.github.com> Date: Thu, 30 Apr 2026 16:12:45 +0900 Subject: [PATCH 3/3] fix: preserve exception cause in RestClient error handling Wrapping original exceptions as causes in RuntimeException constructors across execRequest() and execPost() to retain full stack traces for debugging. --- src/main/java/co/elastic/support/rest/RestClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/co/elastic/support/rest/RestClient.java b/src/main/java/co/elastic/support/rest/RestClient.java index 8c64c8fb..1a6725a5 100644 --- a/src/main/java/co/elastic/support/rest/RestClient.java +++ b/src/main/java/co/elastic/support/rest/RestClient.java @@ -121,7 +121,7 @@ public void close() { client.close(); } } catch (Exception e) { - logger.error("Error occurred closing client connection."); + logger.error("Error occurred closing client connection.", e); } }