Skip to content

Commit 41ec4b2

Browse files
author
Massimo Galbusera
committed
get the root reason when available
1 parent 256ff2c commit 41ec4b2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file based on the
1111

1212
### Improvements
1313
- Set PHP 7.0 as default development version
14+
- Get the root reason from Elasticsearch's error JSON, when available [#1111](https://github.com/ruflin/Elastica/pull/1111)
1415

1516
## [3.2.1](https://github.com/ruflin/Elastica/compare/3.2.0...3.2.1)
1617

lib/Elastica/Response.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,18 @@ public function getError()
9595
return $error;
9696
}
9797

98+
$rootError = $error;
9899
if (isset($error['root_cause'][0])) {
99-
$error = $error['root_cause'][0];
100+
$rootError = $error['root_cause'][0];
100101
}
101102

102-
$message = $error['reason'];
103-
if (isset($error['index'])) {
104-
$message .= ' [index: '.$error['index'].']';
103+
$message = $rootError['reason'];
104+
if (isset($rootError['index'])) {
105+
$message .= ' [index: '.$rootError['index'].']';
106+
}
107+
108+
if (isset($error['reason']) && $rootError['reason'] != $error['reason']) {
109+
$message .= ' [reason: '.$error['reason'].']';
105110
}
106111

107112
return $message;

0 commit comments

Comments
 (0)