Skip to content

Commit 46f95df

Browse files
author
Aubron Wood
authored
Merge pull request #29 from ooglek/empty-body-exception-fix
Fixing empty body not populating Exception message
2 parents b1e8700 + c573c8e commit 46f95df

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
@@ -366,7 +366,7 @@ private function parseResponse($response)
366366
*/
367367
private function parseExceptionResponse($e)
368368
{
369-
$body = $e->getResponse()->getBody(true);
369+
$body = $e->getResponse()->getBody(true)->getContents();
370370
$doc = @simplexml_load_string($body);
371371

372372
if (isset($doc) &&
@@ -390,6 +390,6 @@ private function parseExceptionResponse($e)
390390
);
391391
}
392392

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

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)