Skip to content

Commit

Permalink
return parsing exception 400 for parsing errors
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
  • Loading branch information
Zhangxunmt committed Nov 4, 2023
1 parent bb10a22 commit 3b098d0
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Locale;

import org.opensearch.client.node.NodeClient;
import org.opensearch.OpenSearchParseException;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.ml.common.transport.connector.MLUpdateConnectorAction;
import org.opensearch.ml.common.transport.connector.MLUpdateConnectorRequest;
Expand Down Expand Up @@ -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());
}
}
}

0 comments on commit 3b098d0

Please sign in to comment.