Permalink
Browse files

Merge pull request #21 from rafaelp/master

Handle 429 Status Code
  • Loading branch information...
jbroadway committed Jan 19, 2013
2 parents 252fd8c + 4c8f2c5 commit 820e0967cbaba8789a5cfa03e4a24aa41a830642
Showing with 14 additions and 1 deletion.
  1. +14 −1 ActiveResource.php
View
@@ -647,15 +647,28 @@ function _fetch ($url, $method, $params) {
$res = curl_exec ($ch);
- // Check HTTP status code for denied access
$http_code = curl_getinfo ($ch, CURLINFO_HTTP_CODE);
+
+ // Check HTTP status code for denied access
if ($http_code == 401) {
$this->errno = $http_code;
$this->error = "HTTP Basic: Access denied.";
curl_close ($ch);
return false;
}
+ // Check HTTP status code for rate limit
+ if ($http_code == 429) {
+ if (preg_match ('/Retry-After: ([0-9]+)/', $res, $retry_after)) {
+ sleep(intval($retry_after[1]));
+ return $this->_fetch ($url, $method, $params);
+ }
+ $this->errno = $http_code;
+ $this->error = "Too Many Requests";
+ curl_close ($ch);
+ return false;
+ }
+
if (! $res) {
$this->errno = curl_errno ($ch);
$this->error = curl_error ($ch);

0 comments on commit 820e096

Please sign in to comment.