@@ -667,22 +667,36 @@ private function tryDeserialize500Error($response)
667
667
private function tryDeserializeError ($ response , $ errorClass )
668
668
{
669
669
$ error = $ this ->serializer ->deserialize ($ response ['body ' ], $ response ['transfer_stats ' ]);
670
- if (is_array ($ error ) === true && isset ($ error ['error ' ]['root_cause ' ]) === true ) {
671
- // Try to use root cause first (only grabs the first root cause)
672
- $ root = $ error ['error ' ]['root_cause ' ];
673
- if (isset ($ root ) && isset ($ root [0 ])) {
674
- $ cause = $ root [0 ]['reason ' ];
675
- $ type = $ root [0 ]['type ' ];
676
- } else {
677
- $ cause = $ error ['error ' ]['reason ' ];
678
- $ type = $ error ['error ' ]['type ' ];
670
+ if (is_array ($ error ) === true ) {
671
+ // 2.0 structured exceptions
672
+ if (isset ($ error ['error ' ]['reason ' ]) === true ) {
673
+
674
+ // Try to use root cause first (only grabs the first root cause)
675
+ $ root = $ error ['error ' ]['root_cause ' ];
676
+ if (isset ($ root ) && isset ($ root [0 ])) {
677
+ $ cause = $ root [0 ]['reason ' ];
678
+ $ type = $ root [0 ]['type ' ];
679
+ } else {
680
+ $ cause = $ error ['error ' ]['reason ' ];
681
+ $ type = $ error ['error ' ]['type ' ];
682
+ }
683
+
684
+ $ original = new $ errorClass ($ response ['body ' ], $ response ['status ' ]);
685
+
686
+ return new $ errorClass ("$ type: $ cause " , $ response ['status ' ], $ original );
687
+ } elseif (isset ($ error ['error ' ]) === true ) {
688
+ // <2.0 semi-structured exceptions
689
+ $ original = new $ errorClass ($ response ['body ' ], $ response ['status ' ]);
690
+
691
+ return new $ errorClass ($ error ['error ' ], $ response ['status ' ], $ original );
679
692
}
680
693
681
- $ original = new $ errorClass ($ response ['body ' ], $ response ['status ' ]);
682
- return new $ errorClass ("$ type: $ cause " , $ response ['status ' ], $ original );
694
+ // <2.0 "i just blew up" nonstructured exception
695
+ // $error is an array but we don't know the format, reuse the response body instead
696
+ return new $ errorClass ($ response ['body ' ], $ response ['status ' ]);
683
697
}
684
698
685
- // Response mangled or unexpected, just return the body
699
+ // <2.0 "i just blew up" nonstructured exception
686
700
return new $ errorClass ($ response ['body ' ]);
687
701
}
688
702
}
0 commit comments