Skip to content

Commit

Permalink
Don't throw ClientException on 4XX
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danmichaelo committed Aug 1, 2017
1 parent 4dc54be commit 3cf4c5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,7 +34,7 @@ class Client
protected $userAgent;

/** @var array Custom headers */
protected $headers;
public $headers;

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

$plugins = [new ErrorPlugin()];
$plugins = [];

$this->schema = isset($options['schema'])
? $options['schema']
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit 3cf4c5d

Please sign in to comment.