diff --git a/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java index f38a231218..6e193d6909 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java @@ -40,7 +40,6 @@ import org.opensearch.index.reindex.DeleteByQueryAction; import org.opensearch.index.reindex.DeleteByQueryRequest; import org.opensearch.ml.common.MLModel; -import org.opensearch.ml.common.exception.MLResourceNotFoundException; import org.opensearch.ml.common.exception.MLValidationException; import org.opensearch.ml.common.model.MLModelState; import org.opensearch.ml.common.transport.model.MLModelDeleteAction; @@ -159,10 +158,9 @@ protected void doExecute(Task task, ActionRequest request, ActionListener { actionListener.onFailure(new MLResourceNotFoundException("Fail to find model")); })); + }, e -> { actionListener.onFailure(e); })); } catch (Exception e) { log.error("Failed to delete ML model " + modelId, e); actionListener.onFailure(e); diff --git a/plugin/src/test/java/org/opensearch/ml/action/models/DeleteModelTransportActionTests.java b/plugin/src/test/java/org/opensearch/ml/action/models/DeleteModelTransportActionTests.java index 73bd333985..d08ed7673e 100644 --- a/plugin/src/test/java/org/opensearch/ml/action/models/DeleteModelTransportActionTests.java +++ b/plugin/src/test/java/org/opensearch/ml/action/models/DeleteModelTransportActionTests.java @@ -30,6 +30,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.opensearch.OpenSearchStatusException; import org.opensearch.ResourceNotFoundException; import org.opensearch.action.ActionListener; import org.opensearch.action.bulk.BulkItemResponse; @@ -359,7 +360,7 @@ public void testDeleteModel_CheckModelState() throws IOException { public void testDeleteModel_ModelNotFoundException() throws IOException { doAnswer(invocation -> { ActionListener actionListener = invocation.getArgument(1); - actionListener.onFailure(new Exception()); + actionListener.onFailure(new Exception("Fail to find model")); return null; }).when(client).get(any(), any()); @@ -423,9 +424,9 @@ public void testModelNotFound() throws IOException { return null; }).when(client).get(any(), any()); deleteModelTransportAction.doExecute(null, mlModelDeleteRequest, actionListener); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(IllegalArgumentException.class); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(OpenSearchStatusException.class); verify(actionListener).onFailure(argumentCaptor.capture()); - assertEquals("Failed to find model to delete with the provided model id: test_id", argumentCaptor.getValue().getMessage()); + assertEquals("Failed to find model", argumentCaptor.getValue().getMessage()); } public void testDeleteModelChunks_Success() {