diff --git a/CHANGELOG.md b/CHANGELOG.md index 377dc1c850..c85ff976ec 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file based on the ### Improvements * Added `native_function_invocation` CS rule [#1606](https://github.com/ruflin/Elastica/pull/1606) * Elasticsearch test version changed from 6.5.2 to 6.6.1 [#1620](https://github.com/ruflin/Elastica/pull/1620) +* Added `caused_by` to exception responses to clarify errors [#1623](https://github.com/ruflin/Elastica/pull/1623) ### Deprecated diff --git a/lib/Elastica/Response.php b/lib/Elastica/Response.php index 487e83cb39..6350ceac25 100644 --- a/lib/Elastica/Response.php +++ b/lib/Elastica/Response.php @@ -90,11 +90,21 @@ public function getError() } $rootError = $error; + $message = $rootError['reason']; + if (isset($error['root_cause'][0])) { $rootError = $error['root_cause'][0]; + $message = $rootError['reason']; + + if (isset($error['caused_by'])) { + $message .= sprintf( + ' [%s:%s]', + $error['caused_by']['caused_by']['type'], + $error['caused_by']['caused_by']['reason'] + ); + } } - $message = $rootError['reason']; if (isset($rootError['index'])) { $message .= ' [index: '.$rootError['index'].']'; }