Skip to content

Commit

Permalink
fix error code when failed to delete model
Browse files Browse the repository at this point in the history
Signed-off-by: Bhavana Ramaram <[email protected]>
  • Loading branch information
rbhavna committed Feb 6, 2024
1 parent de0fd99 commit 9064ba1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
} else {
wrappedListener
.onFailure(
new Exception(
"Model cannot be deleted in deploying or deployed state. Try undeploy model first then delete"
new OpenSearchStatusException(
"Model cannot be deleted in deploying or deployed state. Try undeploy model first then delete",
RestStatus.BAD_REQUEST
)
);
}
Expand All @@ -150,8 +151,9 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
} else {
wrappedListener
.onFailure(
new Exception(
"Model cannot be deleted in deploying or deployed state. Try undeploy model first then delete"
new OpenSearchStatusException(
"Model cannot be deleted in deploying or deployed state. Try undeploy model first then delete",
RestStatus.BAD_REQUEST
)
);
}
Expand All @@ -167,7 +169,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
} else {
wrappedListener.onFailure(new OpenSearchStatusException("Failed to find model", RestStatus.NOT_FOUND));
}
}, e -> { wrappedListener.onFailure(e); }));
}, e -> { wrappedListener.onFailure((new OpenSearchStatusException("Failed to find model", RestStatus.NOT_FOUND))); }));
} 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 @@ -280,7 +280,7 @@ public void testDeleteModel_ModelNotFoundException() throws IOException {
deleteModelTransportAction.doExecute(null, mlModelDeleteRequest, actionListener);
ArgumentCaptor<Exception> argumentCaptor = ArgumentCaptor.forClass(Exception.class);
verify(actionListener).onFailure(argumentCaptor.capture());
assertEquals("Fail to find model", argumentCaptor.getValue().getMessage());
assertEquals("Failed to find model", argumentCaptor.getValue().getMessage());
}

public void testDeleteModel_ResourceNotFoundException() throws IOException {
Expand Down

0 comments on commit 9064ba1

Please sign in to comment.