-
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
Conversation
Signed-off-by: Xun Zhang <[email protected]>
Codecov Report
@@ Coverage Diff @@
## 2.x #1593 +/- ##
============================================
+ Coverage 80.64% 80.66% +0.02%
- Complexity 4177 4178 +1
============================================
Files 399 399
Lines 16816 16818 +2
Branches 1815 1815
============================================
+ Hits 13561 13566 +5
+ Misses 2540 2537 -3
Partials 715 715
Flags with carried forward coverage won't be shown. Click here to find out more.
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); | ||
return MLUpdateConnectorRequest.parse(parser, connectorId); | ||
} catch (IllegalStateException illegalStateException) { | ||
throw new OpenSearchParseException(illegalStateException.getMessage()); |
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 the throw new IOException
to throw 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.
Signed-off-by: Xun Zhang <[email protected]>
@@ -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 comment
The 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 comment
The 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 comment
The 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 comment
The 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.
Description
Fix the 500 internal service error reported in the pen test. All parsing errors should return 400 error code showing it's coming from users.
Test:
Issues Resolved
[List any issues this PR will resolve]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.