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