Skip to content

Commit f148afa

Browse files
committed
Fixed CS
1 parent e215a0b commit f148afa

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

src/Elasticsearch/Connections/Connection.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ private function tryDeserializeError(array $response, string $errorClass): Elast
685685
// added json_encode to convert into a string
686686
return new $errorClass(json_encode($response['body']), (int) $response['status']);
687687
}
688+
688689
// 2.0 structured exceptions
689690
if (is_array($error['error']) && array_key_exists('reason', $error['error']) === true) {
690691
// Try to use root cause first (only grabs the first root cause)
@@ -698,31 +699,18 @@ private function tryDeserializeError(array $response, string $errorClass): Elast
698699
}
699700
// added json_encode to convert into a string
700701
$original = new $errorClass(json_encode($response['body']), $response['status']);
702+
701703
return new $errorClass("$type: $cause", (int) $response['status'], $original);
702704
}
703705
// <2.0 semi-structured exceptions
704706
// added json_encode to convert into a string
705707
$original = new $errorClass(json_encode($response['body']), $response['status']);
706-
return new $errorClass($error['error'], (int) $response['status'], $original);
707708

708-
// // 2.0 structured exceptions
709-
// if (is_array($error['error'])) {
710-
// // Try to use root cause first (only grabs the first root cause)
711-
// $root = $error['error']['root_cause'];
712-
// if (isset($root) && isset($root[0])) {
713-
// $cause = $root[0]['reason'];
714-
// $type = $root[0]['type'];
715-
// } else {
716-
// $cause = $error['error']['reason'];
717-
// $type = $error['error']['type'];
718-
// }
719-
// }
720-
// // added json_encode to convert into a string
721-
// $original = new $errorClass(json_encode($response['body']), $response['status']);
722-
723-
// return isset($cause) && isset($type) ?
724-
// new $errorClass("$type: $cause", (int) $response['status'], $original) :
725-
// new $errorClass(json_encode($error['error']), (int) $response['status'], $original);
709+
$errorEncoded = $error['error'];
710+
if (is_array($errorEncoded)) {
711+
$errorEncoded = json_encode($errorEncoded);
712+
}
713+
return new $errorClass($errorEncoded, (int) $response['status'], $original);
726714
}
727715

728716
// if responseBody is not string, we convert it so it can be used as Exception message

tests/Elasticsearch/Tests/Connections/ConnectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ function () {
307307
$tryDeserializeError->setAccessible(true);
308308

309309
$body = '{"error":{"root_cause":[{"type":"master_not_discovered_exception","reason":null}],"type":"master_not_discovered_exception","reason":null},"status":503}';
310-
$response = [
310+
$response = [
311311
'transfer_stats' => [],
312312
'status' => 503,
313313
'body' => $body

0 commit comments

Comments
 (0)