diff --git a/src/Client.php b/src/Client.php index d853347..c5f75f7 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,6 +4,7 @@ use Http\Client\Common\PluginClient; use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; +use Http\Client\Common\Exception\ServerErrorException; use Http\Client\Common\Plugin\ErrorPlugin; use Http\Discovery\MessageFactoryDiscovery; use Http\Message\Authentication\BasicAuth; @@ -33,7 +34,7 @@ class Client protected $userAgent; /** @var array Custom headers */ - protected $headers; + public $headers; /** * @var string|string[] Proxy configuration details. @@ -66,7 +67,7 @@ public function __construct( $this->url = $url; $options = $options ?: array(); - $plugins = [new ErrorPlugin()]; + $plugins = []; $this->schema = isset($options['schema']) ? $options['schema'] @@ -214,6 +215,10 @@ public function request($method, $url) $request = $this->messageFactory->createRequest($method, $url, $this->headers); $response = $this->httpClient->sendRequest($request); + if ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) { + throw new ServerErrorException($response->getReasonPhrase(), $request, $response); + } + return (string) $response->getBody(); } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 7989805..0f0b412 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -143,7 +143,7 @@ public function testHttpHeaders() 'user-agent' => 'Blablabla/0.1', )); - $opts = $sru1->getHttpHeaders(); + $opts = $sru1->headers; $this->assertEquals('application/xml', $opts['Accept']); $this->assertEquals('Blablabla/0.1', $opts['User-Agent']);