@@ -685,7 +685,6 @@ private function tryDeserializeError(array $response, string $errorClass): Elast
685
685
// added json_encode to convert into a string
686
686
return new $ errorClass (json_encode ($ response ['body ' ]), (int ) $ response ['status ' ]);
687
687
}
688
-
689
688
// 2.0 structured exceptions
690
689
if (is_array ($ error ['error ' ]) && array_key_exists ('reason ' , $ error ['error ' ]) === true ) {
691
690
// Try to use root cause first (only grabs the first root cause)
@@ -699,14 +698,31 @@ private function tryDeserializeError(array $response, string $errorClass): Elast
699
698
}
700
699
// added json_encode to convert into a string
701
700
$ original = new $ errorClass (json_encode ($ response ['body ' ]), $ response ['status ' ]);
702
-
703
701
return new $ errorClass ("$ type: $ cause " , (int ) $ response ['status ' ], $ original );
704
702
}
705
703
// <2.0 semi-structured exceptions
706
704
// added json_encode to convert into a string
707
705
$ original = new $ errorClass (json_encode ($ response ['body ' ]), $ response ['status ' ]);
708
-
709
706
return new $ errorClass ($ error ['error ' ], (int ) $ response ['status ' ], $ original );
707
+
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);
710
726
}
711
727
712
728
// if responseBody is not string, we convert it so it can be used as Exception message
0 commit comments