Skip to content

Commit 26ffe2e

Browse files
Use resource already exists exception to avoid logging error message (#137525)
1 parent c925aa0 commit 26ffe2e

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/ModelRegistryIT.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.inference.integration;
99

1010
import org.elasticsearch.ElasticsearchStatusException;
11+
import org.elasticsearch.ResourceAlreadyExistsException;
1112
import org.elasticsearch.ResourceNotFoundException;
1213
import org.elasticsearch.TransportVersion;
1314
import org.elasticsearch.action.ActionListener;
@@ -906,7 +907,7 @@ public void testStoreModel_ThrowsException_WhenFailureIsAVersionConflict() {
906907
var model = TestModel.createRandomInstance();
907908
assertStoreModel(modelRegistry, model);
908909

909-
var exception = expectThrows(ElasticsearchStatusException.class, () -> assertStoreModel(modelRegistry, model));
910+
var exception = expectThrows(ResourceAlreadyExistsException.class, () -> assertStoreModel(modelRegistry, model));
910911
assertThat(exception.status(), Matchers.is(RestStatus.BAD_REQUEST));
911912
assertThat(
912913
exception.getMessage(),
@@ -941,7 +942,7 @@ public void testStoreModel_DoesNotDeleteIndexDocs_WhenModelAlreadyExists() {
941942
PlainActionFuture<Boolean> secondStoreListener = new PlainActionFuture<>();
942943
modelRegistry.storeModel(model, secondStoreListener, TimeValue.THIRTY_SECONDS);
943944

944-
var exception = expectThrows(ElasticsearchStatusException.class, () -> secondStoreListener.actionGet(TimeValue.THIRTY_SECONDS));
945+
var exception = expectThrows(ResourceAlreadyExistsException.class, () -> secondStoreListener.actionGet(TimeValue.THIRTY_SECONDS));
945946
assertThat(exception.getMessage(), containsString("already exists"));
946947
assertThat(exception.status(), Matchers.is(RestStatus.BAD_REQUEST));
947948
assertIndicesContainExpectedDocsCount(model, 2);
@@ -964,7 +965,7 @@ private void storeCorruptedModelThenStoreModel(boolean storeSecrets) {
964965
PlainActionFuture<Boolean> storeListener = new PlainActionFuture<>();
965966
modelRegistry.storeModel(model, storeListener, TimeValue.THIRTY_SECONDS);
966967

967-
var exception = expectThrows(ElasticsearchStatusException.class, () -> storeListener.actionGet(TimeValue.THIRTY_SECONDS));
968+
var exception = expectThrows(ResourceAlreadyExistsException.class, () -> storeListener.actionGet(TimeValue.THIRTY_SECONDS));
968969
assertThat(exception.getMessage(), containsString("already exists"));
969970
assertThat(exception.status(), Matchers.is(RestStatus.BAD_REQUEST));
970971

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistry.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,7 @@ private void storeModel(Model model, boolean updateClusterState, ActionListener<
670670

671671
var failureItem = firstFailureResponse.get();
672672
if (ExceptionsHelper.unwrapCause(failureItem.failureCause()) instanceof VersionConflictEngineException) {
673-
delegate.onFailure(
674-
new ElasticsearchStatusException(
675-
"Inference endpoint [{}] already exists",
676-
RestStatus.BAD_REQUEST,
677-
failureItem.failureCause(),
678-
failureItem.inferenceId()
679-
)
680-
);
673+
delegate.onFailure(new ResourceAlreadyExistsException("Inference endpoint [{}] already exists", failureItem.inferenceId()));
681674
return;
682675
}
683676

0 commit comments

Comments
 (0)