Navigation Menu

Skip to content

Commit

Permalink
Revert "Simplify error parsing now that we don't support <2.0 errors"
Browse files Browse the repository at this point in the history
This reverts commit a6d896b.
  • Loading branch information
polyfractal committed Nov 2, 2016
1 parent 90fbd53 commit fd38538
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/Elasticsearch/Connections/Connection.php
Expand Up @@ -667,22 +667,36 @@ private function tryDeserialize500Error($response)
private function tryDeserializeError($response, $errorClass)
{
$error = $this->serializer->deserialize($response['body'], $response['transfer_stats']);
if (is_array($error) === true && isset($error['error']['root_cause']) === true) {
// Try to use root cause first (only grabs the first root cause)
$root = $error['error']['root_cause'];
if (isset($root) && isset($root[0])) {
$cause = $root[0]['reason'];
$type = $root[0]['type'];
} else {
$cause = $error['error']['reason'];
$type = $error['error']['type'];
if (is_array($error) === true) {
// 2.0 structured exceptions
if (isset($error['error']['reason']) === true) {

// Try to use root cause first (only grabs the first root cause)
$root = $error['error']['root_cause'];
if (isset($root) && isset($root[0])) {
$cause = $root[0]['reason'];
$type = $root[0]['type'];
} else {
$cause = $error['error']['reason'];
$type = $error['error']['type'];
}

$original = new $errorClass($response['body'], $response['status']);

return new $errorClass("$type: $cause", $response['status'], $original);
} elseif (isset($error['error']) === true) {
// <2.0 semi-structured exceptions
$original = new $errorClass($response['body'], $response['status']);

return new $errorClass($error['error'], $response['status'], $original);
}

$original = new $errorClass($response['body'], $response['status']);
return new $errorClass("$type: $cause", $response['status'], $original);
// <2.0 "i just blew up" nonstructured exception
// $error is an array but we don't know the format, reuse the response body instead
return new $errorClass($response['body'], $response['status']);
}

// Response mangled or unexpected, just return the body
// <2.0 "i just blew up" nonstructured exception
return new $errorClass($response['body']);
}
}

0 comments on commit fd38538

Please sign in to comment.