Skip to content

Commit

Permalink
Fixes #31: Wrong parameters error when TimeoutException is thrown (#32)
Browse files Browse the repository at this point in the history
* Fixes #31: Wrong parameters error when TimeoutException is thrown
  • Loading branch information
mrmiagi authored and joelwurtz committed Nov 30, 2017
1 parent 26075bf commit e2833e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/Exception/StreamException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,36 @@
namespace Http\Client\Socket\Exception;

use Http\Client\Exception;
use Psr\Http\Message\RequestInterface;

class StreamException extends \RuntimeException implements Exception
{
/**
* The request object.
*
* @var RequestInterface
*/
private $request;

/**
* Accepts an optional request object as 4th param.
*
* @param string $message
* @param int $code
* @param Exception $previous
* @param RequestInterface $request
*/
public function __construct($message = null, $code = null, $previous = null, RequestInterface $request = null)
{
$this->request = $request;
parent::__construct($message, $code, $previous);
}

/**
* @return \Psr\Http\Message\RequestInterface|null
*/
final public function getRequest()
{
return $this->request;
}
}
2 changes: 1 addition & 1 deletion src/ResponseReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function readResponse(RequestInterface $request, $socket)
$metadatas = stream_get_meta_data($socket);

if (array_key_exists('timed_out', $metadatas) && true === $metadatas['timed_out']) {
throw new TimeoutException('Error while reading response, stream timed out', $request);
throw new TimeoutException('Error while reading response, stream timed out', null, null, $request);
}

$parts = explode(' ', array_shift($headers), 3);
Expand Down

0 comments on commit e2833e0

Please sign in to comment.