Skip to content

Commit

Permalink
proper exception when unable to connect and invalid status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandresalome committed Oct 8, 2013
1 parent 15dd93f commit f15c70d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ public function requestRaw($method, $url, $parameters = array())

curl_setopt_array($curl, $options);

return curl_exec($curl);
$result = curl_exec($curl);

$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($statusCode === 200 || $statusCode === 204 || ($statusCode >= 300 && $statusCode <= 303)) {
return $result;
}

if (0 === $statusCode) {
throw new \RuntimeException(sprintf('Unable to connect to "%s".', $this->url));
}

throw new \RuntimeException(sprintf('Unexpected status code. Expected valid code, got %s.', $statusCode));
}
}

0 comments on commit f15c70d

Please sign in to comment.