diff --git a/plugin/src/main/java/org/opensearch/ml/rest/RestMLUpdateConnectorAction.java b/plugin/src/main/java/org/opensearch/ml/rest/RestMLUpdateConnectorAction.java index 2957740354..0b47b39029 100644 --- a/plugin/src/main/java/org/opensearch/ml/rest/RestMLUpdateConnectorAction.java +++ b/plugin/src/main/java/org/opensearch/ml/rest/RestMLUpdateConnectorAction.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Locale; +import org.opensearch.OpenSearchParseException; import org.opensearch.client.node.NodeClient; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.ml.common.transport.connector.MLUpdateConnectorAction; @@ -68,9 +69,12 @@ private MLUpdateConnectorRequest getRequest(RestRequest request) throws IOExcept String connectorId = getParameterId(request, PARAMETER_CONNECTOR_ID); - XContentParser parser = request.contentParser(); - ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); - - return MLUpdateConnectorRequest.parse(parser, connectorId); + try { + XContentParser parser = request.contentParser(); + ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); + return MLUpdateConnectorRequest.parse(parser, connectorId); + } catch (IllegalStateException illegalStateException) { + throw new OpenSearchParseException(illegalStateException.getMessage()); + } } }