Skip to content

Commit

Permalink
catch ratelimit on github
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolashohm committed Feb 15, 2015
1 parent 58b622e commit 2b52c8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Network/Github.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public function userExists($username = null)
{
$client = clone $this->httpClient;
$client->setUri($this->baseUrl . 'users/' . $username);
return $client->send()->isSuccess();
$response = $client->send();
if (!($response->isSuccess() || $response->getStatusCode() == 404)) {
throw new \Exception('Unexpected response ' . $response->getStatusCode() . ' ' . $response->getBody());
}
return $response->isSuccess();
}

private function fetchUsers($type, $username)
Expand Down
8 changes: 8 additions & 0 deletions test/Networker/Network/GithubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ public function provideUserExists()
[404, false],
];
}

/**
* @expectedException Exception
*/
public function testUserExistsThrowExceptionOnForbidden()
{
$this->testUserExists(403, false);
}
}

0 comments on commit 2b52c8b

Please sign in to comment.