diff --git a/plugin/src/main/java/org/opensearch/ml/rest/RestMLExecuteAction.java b/plugin/src/main/java/org/opensearch/ml/rest/RestMLExecuteAction.java index ae31269800..3284da09b7 100644 --- a/plugin/src/main/java/org/opensearch/ml/rest/RestMLExecuteAction.java +++ b/plugin/src/main/java/org/opensearch/ml/rest/RestMLExecuteAction.java @@ -32,6 +32,7 @@ import org.opensearch.ml.repackage.com.google.common.annotations.VisibleForTesting; import org.opensearch.ml.repackage.com.google.common.collect.ImmutableList; import org.opensearch.ml.settings.MLFeatureEnabledSetting; +import org.opensearch.ml.utils.error.ErrorMessage; import org.opensearch.ml.utils.error.ErrorMessageFactory; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.BytesRestResponse; @@ -130,7 +131,8 @@ private void sendResponse(RestChannel channel, MLExecuteTaskResponse response) t } private void reportError(final RestChannel channel, final Exception e, final RestStatus status) { - channel.sendResponse(new BytesRestResponse(status, ErrorMessageFactory.createErrorMessage(e, status.getStatus()).toString())); + ErrorMessage errorMessage = ErrorMessageFactory.createErrorMessage(e, status.getStatus()); + channel.sendResponse(new BytesRestResponse(RestStatus.fromCode(errorMessage.getStatus()), errorMessage.toString())); } private boolean isClientError(Exception e) { diff --git a/plugin/src/main/java/org/opensearch/ml/utils/error/ErrorMessage.java b/plugin/src/main/java/org/opensearch/ml/utils/error/ErrorMessage.java index 8184b0a835..c81f6202ee 100644 --- a/plugin/src/main/java/org/opensearch/ml/utils/error/ErrorMessage.java +++ b/plugin/src/main/java/org/opensearch/ml/utils/error/ErrorMessage.java @@ -20,6 +20,7 @@ public class ErrorMessage { protected Throwable exception; + @Getter private final int status; @Getter