1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-01-18 05:48:15 +01:00

Merge pull request #1621 from cnanney/master

Don't include summary in exception message when body is empty
This commit is contained in:
Márk Sági-Kazár 2016-10-23 11:32:37 +02:00 committed by GitHub
commit 58219b370b
2 changed files with 13 additions and 1 deletions

View File

@ -131,6 +131,11 @@ class RequestException extends TransferException
}
$size = $body->getSize();
if ($size === 0) {
return null;
}
$summary = $body->read(120);
$body->rewind();

View File

@ -109,6 +109,12 @@ class RequestExceptionTest extends \PHPUnit_Framework_TestCase
$this->assertContains($expected, $e->getMessage());
}
public function testExceptionMessageIgnoresEmptyBody()
{
$e = RequestException::create(new Request('GET', '/'), new Response(500));
$this->assertStringEndsWith('response', $e->getMessage());
}
public function testCreatesExceptionWithoutPrintableBody()
{
$response = new Response(
@ -124,7 +130,8 @@ class RequestExceptionTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('GuzzleHttp\Exception\RequestException', $e);
}
public function testHasStatusCodeAsExceptionCode() {
public function testHasStatusCodeAsExceptionCode()
{
$e = RequestException::create(new Request('GET', '/'), new Response(442));
$this->assertEquals(442, $e->getCode());
}