From 29ec410d6598feefaaecf8c97b47873491c07d15 Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Wed, 16 Oct 2024 09:34:54 -0600 Subject: [PATCH] Review fix --- .../java/org/elasticsearch/http/BulkRestIT.java | 2 +- .../rest/action/document/RestBulkAction.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/BulkRestIT.java b/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/BulkRestIT.java index 67c9f505b2e53..369d0824bdb28 100644 --- a/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/BulkRestIT.java +++ b/qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/BulkRestIT.java @@ -89,7 +89,7 @@ public void testBulkRequestBodyImproperlyTerminated() throws IOException { ); ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request)); assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode()); - assertThat(responseException.getMessage(), containsString("could not parse bulk request body")); + assertThat(responseException.getMessage(), containsString("The bulk request must be terminated by a newline")); } public void testBulkRequest() throws IOException { diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java index fb947f1811c23..34bbb5420f61a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java @@ -139,8 +139,13 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC } } - private static ElasticsearchParseException parseFailureException(Exception e) { - return new ElasticsearchParseException("could not parse bulk request body", e); + private static Exception parseFailureException(Exception e) { + if (e instanceof IllegalArgumentException) { + return e; + } else { + // TODO: Maybe improve in follow-up to be XContentParseException and include line number and column + return new ElasticsearchParseException("could not parse bulk request body", e); + } } static class ChunkHandler implements BaseRestHandler.RequestBodyChunkConsumer {