Skip to content

Commit

Permalink
Fixing instance profile error case
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed May 18, 2015
1 parent 9bee50b commit 2694946
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
15 changes: 6 additions & 9 deletions src/Credentials/InstanceProfileProvider.php
Expand Up @@ -73,15 +73,12 @@ private function request($url)
return $fn($request, ['timeout' => $this->timeout])
->then(function (ResponseInterface $response) {
return (string) $response->getBody();
})->otherwise(function ($reason) {
if ($reason instanceof \Exception) {
throw new CredentialsException(
$this->createErrorMessage($reason->getMessage()),
$reason->getCode(),
$reason
);
}
throw new CredentialsException($this->createErrorMessage($reason));
})->otherwise(function (array $reason) {
$reason = $reason['exception'];
$msg = $reason->getMessage();
throw new CredentialsException(
$this->createErrorMessage($msg, 0, $reason)
);
});
}

Expand Down
10 changes: 7 additions & 3 deletions tests/Credentials/InstanceProfileProviderTest.php
Expand Up @@ -69,8 +69,10 @@ public function testSeedsInitialCredentials()
*/
public function testRejectsIfProfileIsNotAvailable()
{
$client = function (RequestInterface $req, array $options) use (&$responses) {
return Promise\rejection_for('error');
$client = function () use (&$responses) {
return Promise\rejection_for([
'exception' => new \Exception('error')
]);
};
$p = new InstanceProfileProvider(['client' => $client]);
$p()->wait();
Expand All @@ -83,7 +85,9 @@ public function testRejectsIfProfileIsNotAvailable()
public function testThrowsExceptionIfCredentialsNotAvailable()
{
$client = function () use (&$responses) {
return Promise\rejection_for('error');
return Promise\rejection_for([
'exception' => new \Exception('error')
]);
};
$args['client'] = $client;
$args['profile'] = 'foo';
Expand Down

0 comments on commit 2694946

Please sign in to comment.