private function _dispatchRequest($request)
{
// track the number of requests across instances
self::$requestCount++;
$timestart = microtime(true);
$response = self::transport()->send($request);
// pass the response through the filter chain
foreach ($this->_filters as $filter) {
$response = $filter->response($response);
}
$httpCode = $response->getStatus()->getCode();
$location = $response->getHeaders()->value('Location');
$body = $response->getBody();
// track the time taken across instances
self::$requestTime += microtime(true) - $timestart;
// process a redirect if needed
if ($httpCode < 400 && $location) {
return $this->_redirect($location);
} else {
$this->_redirects = 0;
}
// translate error code to a typed exception
if ($httpCode == 500) {
throw new Error\InternalServerError($body);
} elseif ($httpCode == 400) {
throw new Error\BadRequest($body);
} elseif ($httpCode == 401) {
throw new Error\Unauthorized($body);
} elseif ($httpCode == 404) {
throw new Error\NotFound($body);
} else {
if ($httpCode >= 300) {
throw new Error($body, $httpCode);
}
}
return $response;
}