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

[BUG] RestClientTransport.getHighLevelResponse() Doesn't Handle 404s/Re-throw Error if Json Parsing Fails #1265

Open
kaden-powell opened this issue Nov 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kaden-powell
Copy link

kaden-powell commented Nov 5, 2024

What is the bug?

When using the Java client, calls to our cluster for a non-existent document throw a JsonParseException (note that upon further investigation, this is likely due to some additional wrappers our system uses that substitute unformatted text for the JSON---still, handling 404s and providing a more foolproof error-catching seem like they may be good practice).

How can one reproduce the bug?

Use the OpenSearch client to perform a get request on a document that doesn't exist in the cluster.

What is the expected behavior?

Response contains actionable information (e.g. status of 404, type of HttpNotFoundException, etc.). Likely, throw a new TransportException like it does for 403 or 401 statuses.

 if (statusCode == HttpStatus.SC_FORBIDDEN) {
    throw new TransportException("Forbidden access", new ResponseException(clientResp));
} else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
    throw new TransportException("Unauthorized access", new ResponseException(clientResp));

Notably, the final attempt to decode the error response only catches MissingRequiredPropertyException, so if there are other Json parsing issues of the entity.Content, they are not handled by throw new TransportException("Failed to decode error response", new ResponseException(clientResp));

Seems that this code should probably:

  1. Explicitly handle 404s, similar to how it handles other 4xx statuses.
  2. More generally catch errors at the bottom of the attempts to decode so that JsonParsingExceptions/other exceptions aren't thrown

What is your host/environment?

MacOS 14.7, Java 17, OpenSearch Client 2.11

@kaden-powell kaden-powell added bug Something isn't working untriaged labels Nov 5, 2024
@Xtansia Xtansia removed the untriaged label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants