-
Notifications
You must be signed in to change notification settings - Fork 138
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
import static org.mockito.Mockito.when; | ||
import static org.opensearch.ml.utils.MLExceptionUtils.REMOTE_INFERENCE_DISABLED_ERR_MSG; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -25,6 +24,7 @@ | |
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.opensearch.OpenSearchParseException; | ||
import org.opensearch.action.update.UpdateResponse; | ||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.common.settings.Settings; | ||
|
@@ -114,8 +114,15 @@ public void testUpdateConnectorRequest() throws Exception { | |
assertEquals("2", updateConnectorRequest.getUpdateContent().getVersion()); | ||
} | ||
|
||
public void testUpdateConnectorRequestWithParsingException() throws Exception { | ||
exceptionRule.expect(OpenSearchParseException.class); | ||
exceptionRule.expectMessage("Can't get text on a VALUE_NULL"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious where are we setting this message? Can we have more readable message from customer's point of view? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the message from the XContentParser in OpenSearch, which contains the exact line and coordinate where the null comes from. exceptionRule.expectMessage only checks if the real message contains this "Can't get text on a VALUE_NULL". The means the real message returned to customer is more explanatory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the clarification? Just out of curiosity, do we know what's the final message we send to customer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please check the description of the PR which has the exact coordinate of the error. Also please note this is one example of the paring exception. |
||
RestRequest request = getRestRequestWithNullValue(); | ||
restMLUpdateConnectorAction.handleRequest(request, channel, client); | ||
} | ||
|
||
public void testUpdateConnectorRequestWithEmptyContent() throws Exception { | ||
exceptionRule.expect(IOException.class); | ||
exceptionRule.expect(OpenSearchParseException.class); | ||
exceptionRule.expectMessage("Failed to update connector: Request body is empty"); | ||
RestRequest request = getRestRequestWithEmptyContent(); | ||
restMLUpdateConnectorAction.handleRequest(request, channel, client); | ||
|
@@ -152,6 +159,20 @@ private RestRequest getRestRequest() { | |
return request; | ||
} | ||
|
||
private RestRequest getRestRequestWithNullValue() { | ||
RestRequest.Method method = RestRequest.Method.POST; | ||
String requestContent = "{\"version\":\"2\",\"description\":null}"; | ||
Map<String, String> params = new HashMap<>(); | ||
params.put("connector_id", "test_connectorId"); | ||
RestRequest request = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) | ||
.withMethod(method) | ||
.withPath("/_plugins/_ml/connectors/_update/{connector_id}") | ||
.withParams(params) | ||
.withContent(new BytesArray(requestContent), XContentType.JSON) | ||
.build(); | ||
return request; | ||
} | ||
|
||
private RestRequest getRestRequestWithEmptyContent() { | ||
RestRequest.Method method = RestRequest.Method.POST; | ||
Map<String, String> params = new HashMap<>(); | ||
|
There was a problem hiding this comment.
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 thethrow new IOException
tothrow new OpenSearchParseException
?There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.