From 2a2aad2dc4ee62c8ce36fe2751dbd4bf2f663ab8 Mon Sep 17 00:00:00 2001 From: Massimo Galbusera Date: Tue, 14 Jun 2016 14:29:56 +0200 Subject: [PATCH] get the root reason when available --- lib/Elastica/Response.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Elastica/Response.php b/lib/Elastica/Response.php index 7e99b07a83..50faa6a8ab 100644 --- a/lib/Elastica/Response.php +++ b/lib/Elastica/Response.php @@ -96,13 +96,18 @@ public function getError() return $error; } + $root_error = $error; if (isset($error['root_cause'][0])) { - $error = $error['root_cause'][0]; + $root_error = $error['root_cause'][0]; } - $message = $error['reason']; - if (isset($error['index'])) { - $message .= ' [index: '.$error['index'].']'; + $message = $root_error['reason']; + if (isset($root_error['index'])) { + $message .= ' [index: '.$root_error['index'].']'; + } + + if (isset($error['reason'])) { + $message .= ' [reason: '.$error['reason'].']'; } return $message;