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] JsonException occurs when OpenSearch returns an error response #318

Open
tn2222 opened this issue Mar 1, 2025 · 0 comments
Open
Labels
bug Something isn't working untriaged

Comments

@tn2222
Copy link

tn2222 commented Mar 1, 2025

What is the bug?

When attempting to retrieve a document using the get() method in Client.php of opensearch-php, if the server returns an error (e.g., 502 Bad Gateway), the response is in HTML format.

During the deserialization of the response body, it appears that the content type is being checked. However, the response is being incorrectly identified as JSON, causing json_decode() to be executed on the HTML response.

As a result, proper error handling does not occur when the OpenSearch server fails, which may lead to application crashes if exception handling is not implemented.

How can one reproduce the bug?

  1. Put a high load on OpenSearch to trigger a 502 Bad Gateway error.
  2. Call the get() method in opensearch-php.
  3. The response returned is an HTML 502 Bad Gateway page.
  4. json_decode() is executed, resulting in a JsonException with a Syntax error.

What is the expected behavior?

Proper error handling should occur when OpenSearch returns an error response.

What is your host/environment?

OS: amazon linux2
php version: 8.3
OpenSearch version: 1.2

Do you have any screenshots?

no

Do you have any additional context?

no

@tn2222 tn2222 added bug Something isn't working untriaged labels Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged
Projects
None yet
Development

No branches or pull requests

1 participant