@@ -21,9 +21,18 @@ class IntercomException extends BadResponseException
2121 */
2222 public static function factory (RequestInterface $ request , Response $ response )
2323 {
24- if (!static ::isValidIntercomError ($ response ->json ())) {
25- $ label = 'Unsuccessful response ' ;
26- $ class = __CLASS__ ;
24+ $ response_json = $ response ->json ();
25+ $ intercom_unavailable_error = NULL ;
26+
27+ if (!static ::isValidIntercomError ($ response_json )) {
28+ if ($ response ->isServerError ()) {
29+ $ label = 'Server error response ' ;
30+ $ class = __NAMESPACE__ . '\\ServerErrorResponseException ' ;
31+ $ intercom_unavailable_error = 'Service Unavailable: Back-end server is at capacity ' ;
32+ } else {
33+ $ label = 'Unsuccessful response ' ;
34+ $ class = __CLASS__ ;
35+ }
2736 } elseif ($ response ->isClientError ()) {
2837 $ label = 'Client error response ' ;
2938 $ class = __NAMESPACE__ . '\\ClientErrorResponseException ' ;
@@ -49,8 +58,12 @@ public static function factory(RequestInterface $request, Response $response)
4958 $ e ->setRequest ($ request );
5059
5160 // Sets the errors if the error response is the standard Intercom error type
52- if (static ::isValidIntercomError ($ response ->json ())) {
53- $ e ->setErrors ($ response ->json ()['errors ' ]);
61+ if (static ::isValidIntercomError ($ response_json )) {
62+ $ e ->setErrors ($ response_json ['errors ' ]);
63+ } elseif ($ intercom_unavailable_error != NULL ) {
64+ $ e ->setErrors ([array (
65+ 'code ' => 'service_unavailable ' ,
66+ "message " => $ intercom_unavailable_error )]);
5467 }
5568
5669 return $ e ;
0 commit comments