Skip to content

Commit

Permalink
leftover in the 404 Not Found return error
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
  • Loading branch information
Zhangxunmt authored and zane-neo committed Sep 1, 2023
1 parent ef4ba2d commit af0f6f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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;
Expand Down Expand Up @@ -159,10 +158,9 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
actionListener.onFailure(e);
}
} else {
actionListener
.onFailure(new IllegalArgumentException("Failed to find model to delete with the provided model id: " + modelId));
actionListener.onFailure(new OpenSearchStatusException("Failed to find model", RestStatus.NOT_FOUND));
}
}, e -> { 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.bulk.BulkItemResponse;
import org.opensearch.action.delete.DeleteResponse;
Expand Down Expand Up @@ -332,7 +333,7 @@ public void testDeleteModel_CheckModelState() throws IOException {
public void testDeleteModel_ModelNotFoundException() throws IOException {
doAnswer(invocation -> {
ActionListener<GetResponse> actionListener = invocation.getArgument(1);
actionListener.onFailure(new Exception());
actionListener.onFailure(new Exception("Fail to find model"));
return null;
}).when(client).get(any(), any());

Expand Down Expand Up @@ -396,9 +397,9 @@ public void testModelNotFound() throws IOException {
return null;
}).when(client).get(any(), any());
deleteModelTransportAction.doExecute(null, mlModelDeleteRequest, actionListener);
ArgumentCaptor<IllegalArgumentException> argumentCaptor = ArgumentCaptor.forClass(IllegalArgumentException.class);
ArgumentCaptor<OpenSearchStatusException> 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() {
Expand Down

0 comments on commit af0f6f7

Please sign in to comment.