opensearch-project / opensearch-php

Official PHP Client for OpenSearch
Other
99 stars 56 forks source link

[BUG] PHP warning `Undefined array key "root_cause"` in Connection::tryDeserializeError() #167

Closed drunken-monkey closed 6 months ago

drunken-monkey commented 10 months ago

What is the bug?

The code for “2.0 structured exceptions” is faulty in \OpenSearch\Connections\Connection::tryDeserializeError(). It will produce a warning (Undefined array key "root_cause") if $error['error']['root_cause'] is not set.

This happens, e.g., when the OpenSearch server returns a 403 error status. In this case, the error key of the response contains just the keys reason and type.

How can one reproduce the bug?

  1. Configure your OpenSearch server to require authentification
  2. Specify wrong auth details when creating the client object in PHP
  3. Upon sending a request (which the server rejects with 403), you will see the PHP warning Undefined array key "root_cause".

What is the expected behavior?

Erorr responses without root_cause should be handled without producing a PHP warning.

What is your host/environment?