Commit dee0c35c authored by Sebastian Kehr's avatar Sebastian Kehr 🚣🏼
Browse files

Catch all zend http exceptions when and reset parameters after sending request.

parent 15cd9611
......@@ -7,7 +7,7 @@ use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Request\Serializer;
use Zend\Http\Client as ZendClient;
use Zend\Http\Exception\RuntimeException;
use Zend\Http\Exception\ExceptionInterface as ZendException;
use Zend\Http\Request as ZendRequest;
use Zend\Psr7Bridge\Psr7Response;
......@@ -31,18 +31,18 @@ class Client implements ClientInterface
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
$requestString = Serializer::toString($request);
$zendRequest = ZendRequest::fromString($requestString);
$serializedRequest = Serializer::toString($request);
$zendRequest = ZendRequest::fromString($serializedRequest);
$zendRequest->getUri()->setHost($request->getUri()->getHost());
try {
$zendResponse = $this->zendClient->send($zendRequest);
} catch (RuntimeException $e) {
throw new ClientException($e->getMessage(), $e->getCode(), $e);
} catch (ZendException $exception) {
throw new ClientException($exception->getMessage(), null, $exception);
}
$this->zendClient->resetParameters(true);
return Psr7Response::fromZend($zendResponse);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment