diff --git a/src/Credentials/InstanceProfileProvider.php b/src/Credentials/InstanceProfileProvider.php index 23d7ff3f94..38a6c532d5 100644 --- a/src/Credentials/InstanceProfileProvider.php +++ b/src/Credentials/InstanceProfileProvider.php @@ -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) + ); }); } diff --git a/tests/Credentials/InstanceProfileProviderTest.php b/tests/Credentials/InstanceProfileProviderTest.php index d70ec2a65a..020b734a4c 100644 --- a/tests/Credentials/InstanceProfileProviderTest.php +++ b/tests/Credentials/InstanceProfileProviderTest.php @@ -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(); @@ -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';