diff --git a/src/Rest/RestClient.php b/src/Rest/RestClient.php index b3638f28a91f90971758f4f7b941c78f827b6ff9..1c81b578064d7450c501bb9b3db981bdb4a28b9d 100644 --- a/src/Rest/RestClient.php +++ b/src/Rest/RestClient.php @@ -90,29 +90,27 @@ class RestClient { catch (RequestException $e) { // RequestException gets thrown for any response status but 2XX. $this->response = $e->getResponse(); - switch ($this->response->getStatusCode()) { - case 401: - // The session ID or OAuth token used has expired or is invalid: refresh - // token. If refreshToken() throws an exception, or if apiHttpRequest() - // throws anything but a RequestException, let it bubble up. - $this->refreshToken(); - try { - $this->response = new RestResponse($this->apiHttpRequest($path, $params, $method)); - } - catch (RequestException $e) { - $this->response = $e->getResponse(); - throw $e; - } - break; - default: - // Any exceptions besides 401 we bubble up to the caller. - throw $e; + // Any exceptions besides 401 get bubbled up. + if ($this->response->getStatusCode() != 401) { + throw $e; + } + + // The session ID or OAuth token used has expired or is invalid: refresh + // token. If refreshToken() throws an exception, or if apiHttpRequest() + // throws anything but a RequestException, let it bubble up. + $this->refreshToken(); + try { + $this->response = new RestResponse($this->apiHttpRequest($path, $params, $method)); + } + catch (RequestException $e) { + $this->response = $e->getResponse(); + throw $e; } } if (empty($this->response) - || !in_array($this->response->getStatusCode(), [200, 201, 204])) { + || ((int)floor($this->response->getStatusCode() / 100)) != 2) { throw new Exception('Unknown error occurred during API call'); }