diff --git a/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/ModelRegistryIT.java b/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/ModelRegistryIT.java index 67d67183a37e3..4f53559dbba02 100644 --- a/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/ModelRegistryIT.java +++ b/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/ModelRegistryIT.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.inference.integration; import org.elasticsearch.ElasticsearchStatusException; +import org.elasticsearch.ResourceAlreadyExistsException; import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.TransportVersion; import org.elasticsearch.action.ActionListener; @@ -906,7 +907,7 @@ public void testStoreModel_ThrowsException_WhenFailureIsAVersionConflict() { var model = TestModel.createRandomInstance(); assertStoreModel(modelRegistry, model); - var exception = expectThrows(ElasticsearchStatusException.class, () -> assertStoreModel(modelRegistry, model)); + var exception = expectThrows(ResourceAlreadyExistsException.class, () -> assertStoreModel(modelRegistry, model)); assertThat(exception.status(), Matchers.is(RestStatus.BAD_REQUEST)); assertThat( exception.getMessage(), @@ -941,7 +942,7 @@ public void testStoreModel_DoesNotDeleteIndexDocs_WhenModelAlreadyExists() { PlainActionFuture secondStoreListener = new PlainActionFuture<>(); modelRegistry.storeModel(model, secondStoreListener, TimeValue.THIRTY_SECONDS); - var exception = expectThrows(ElasticsearchStatusException.class, () -> secondStoreListener.actionGet(TimeValue.THIRTY_SECONDS)); + var exception = expectThrows(ResourceAlreadyExistsException.class, () -> secondStoreListener.actionGet(TimeValue.THIRTY_SECONDS)); assertThat(exception.getMessage(), containsString("already exists")); assertThat(exception.status(), Matchers.is(RestStatus.BAD_REQUEST)); assertIndicesContainExpectedDocsCount(model, 2); @@ -964,7 +965,7 @@ private void storeCorruptedModelThenStoreModel(boolean storeSecrets) { PlainActionFuture storeListener = new PlainActionFuture<>(); modelRegistry.storeModel(model, storeListener, TimeValue.THIRTY_SECONDS); - var exception = expectThrows(ElasticsearchStatusException.class, () -> storeListener.actionGet(TimeValue.THIRTY_SECONDS)); + var exception = expectThrows(ResourceAlreadyExistsException.class, () -> storeListener.actionGet(TimeValue.THIRTY_SECONDS)); assertThat(exception.getMessage(), containsString("already exists")); assertThat(exception.status(), Matchers.is(RestStatus.BAD_REQUEST)); diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistry.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistry.java index e556b1db9ecd8..66d8db95fd267 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistry.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistry.java @@ -670,14 +670,7 @@ private void storeModel(Model model, boolean updateClusterState, ActionListener< var failureItem = firstFailureResponse.get(); if (ExceptionsHelper.unwrapCause(failureItem.failureCause()) instanceof VersionConflictEngineException) { - delegate.onFailure( - new ElasticsearchStatusException( - "Inference endpoint [{}] already exists", - RestStatus.BAD_REQUEST, - failureItem.failureCause(), - failureItem.inferenceId() - ) - ); + delegate.onFailure(new ResourceAlreadyExistsException("Inference endpoint [{}] already exists", failureItem.inferenceId())); return; }