Skip to content

Commit

Permalink
refactored exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jan 23, 2017
1 parent 88b224e commit 9ef2129
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
11 changes: 5 additions & 6 deletions src/RequestErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

/**
* Request error exception.
*
* For exceptions during request sending.
*/
class RequestErrorException extends Exception
{
/**
* @var array The API response
* @return RequestInterface
*/
public $response;

public function __construct($message, array $errorInfo = [], $code = 0, \Exception $previous = null)
public function getRequest()
{
parent::__construct($message, $errorInfo, $code, $previous);
$this->response = $this->errorInfo['response'];
return $this->errorInfo['request'];
}
}
11 changes: 5 additions & 6 deletions src/ResponseErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

/**
* Response error exception.
*
* For exceptions during response processing.
*/
class ResponseErrorException extends Exception
{
/**
* @var array The API response
* @return ResponseInterface
*/
public $response;

public function __construct($message, array $errorInfo = [], $code = 0, \Exception $previous = null)
public function getResponse()
{
parent::__construct($message, $errorInfo, $code, $previous);
$this->response = $this->errorInfo['response'];
return $this->errorInfo['response'];
}
}
3 changes: 2 additions & 1 deletion src/stream/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public function send($options = [])
$responseHeaders = $http_response_header;
fclose($stream);
} catch (\Exception $e) {
throw new RequestErrorException($e->getMessage(), $e->getCode(), $e);
$errorInfo = ['request' => $this];
throw new RequestErrorException($e->getMessage(), $errorInfo, $e->getCode(), $e);
}

return new $this->responseClass($this, $responseContent, $responseHeaders);
Expand Down

0 comments on commit 9ef2129

Please sign in to comment.