Skip to content

Commit 3cf4c5d

Browse files
committed
Don't throw ClientException on 4XX
Some SRU servers return 4XX whenever there is a diagnostic message, including zero results responses. We want to handle those responses by our Response class.
1 parent 4dc54be commit 3cf4c5d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Client.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Http\Client\Common\PluginClient;
55
use Http\Client\HttpClient;
66
use Http\Discovery\HttpClientDiscovery;
7+
use Http\Client\Common\Exception\ServerErrorException;
78
use Http\Client\Common\Plugin\ErrorPlugin;
89
use Http\Discovery\MessageFactoryDiscovery;
910
use Http\Message\Authentication\BasicAuth;
@@ -33,7 +34,7 @@ class Client
3334
protected $userAgent;
3435

3536
/** @var array Custom headers */
36-
protected $headers;
37+
public $headers;
3738

3839
/**
3940
* @var string|string[] Proxy configuration details.
@@ -66,7 +67,7 @@ public function __construct(
6667
$this->url = $url;
6768
$options = $options ?: array();
6869

69-
$plugins = [new ErrorPlugin()];
70+
$plugins = [];
7071

7172
$this->schema = isset($options['schema'])
7273
? $options['schema']
@@ -214,6 +215,10 @@ public function request($method, $url)
214215
$request = $this->messageFactory->createRequest($method, $url, $this->headers);
215216
$response = $this->httpClient->sendRequest($request);
216217

218+
if ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
219+
throw new ServerErrorException($response->getReasonPhrase(), $request, $response);
220+
}
221+
217222
return (string) $response->getBody();
218223
}
219224
}

tests/ClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function testHttpHeaders()
143143
'user-agent' => 'Blablabla/0.1',
144144
));
145145

146-
$opts = $sru1->getHttpHeaders();
146+
$opts = $sru1->headers;
147147

148148
$this->assertEquals('application/xml', $opts['Accept']);
149149
$this->assertEquals('Blablabla/0.1', $opts['User-Agent']);

0 commit comments

Comments
 (0)