Skip to content

Commit c573c8e

Browse files
committed
Fixing empty body not populating Exception message
1 parent 74ac3ee commit c573c8e

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

core/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private function parseResponse($response)
365365
*/
366366
private function parseExceptionResponse($e)
367367
{
368-
$body = $e->getResponse()->getBody(true);
368+
$body = $e->getResponse()->getBody(true)->getContents();
369369
$doc = @simplexml_load_string($body);
370370

371371
if (isset($doc) &&
@@ -389,6 +389,6 @@ private function parseExceptionResponse($e)
389389
);
390390
}
391391

392-
throw new ResponseException($body, $e->getResponse()->getStatusCode());
392+
throw new ResponseException($e->getMessage(), $e->getResponse()->getStatusCode());
393393
}
394394
}

tests/BadCredsTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
use GuzzleHttp\Handler\MockHandler;
3+
use GuzzleHttp\HandlerStack;
4+
use GuzzleHttp\Psr7\Response;
5+
use GuzzleHttp\Middleware;
6+
7+
class BadCredsTest extends PHPUnit_Framework_TestCase {
8+
public static $container;
9+
public static $client;
10+
public static $index = 0;
11+
12+
public static function setUpBeforeClass() {
13+
$mock = new MockHandler([
14+
new Response(401, [], ""),
15+
]);
16+
17+
self::$container = [];
18+
$history = Middleware::history(self::$container);
19+
$handler = HandlerStack::create($mock);
20+
$handler->push($history);
21+
22+
self::$client = new Iris\Client("test", "test", Array('url' => 'https://test.dashboard.bandwidth.com/', 'handler' => $handler));
23+
}
24+
25+
/**
26+
* @expectedException Iris\ResponseException
27+
* @expectedExceptionMessageRegExp #^.*resulted in a.*$#
28+
* @expectedExceptionCode 401
29+
*/
30+
public function testAuthFail() {
31+
$c = new \Iris\Cities(self::$client);
32+
try {
33+
$cities = $c->getList(["state" => "NC"]);
34+
} catch (ClientException $e) {
35+
$this->assertTrue(!empty($e->getMessage()));
36+
throw $e;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)