Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return parsing exception 400 for parsing errors #1593

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm in line 67 IOException could also throw a 500 status code, would you mind changing the throw new IOException to throw new OpenSearchParseException?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on previous comment. Don't we need to add corresponding test as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch. Already updated in the new commit. The UT tests are added too.

}
}
}
Loading