Skip to content
Snippets Groups Projects
Commit 5e7543ee authored by Aaron Bauman's avatar Aaron Bauman
Browse files

Tweak RestClient response handling for readability

parent 80e4f7b6
No related branches found
No related tags found
No related merge requests found
......@@ -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');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment