opensearch-project / opensearch-project/opensearch-java

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

Open
#1,265 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
165
Forks
250
Avg merge
1d 18h
Merged PRs (30d)
26

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating RestClientTransport.getHighLevelResponse() and read the existing handling for 401 and 403 responses. Reproduce a get request for a missing document, then verify that 404 responses and failures while decoding the error entity produce actionable TransportException information rather than an uncaught JSON parsing error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.