Skip to content

Commit

Permalink
Merge pull request #24 from magus424/update-exception-handling
Browse files Browse the repository at this point in the history
Update Exception handling to include previous Exception.
  • Loading branch information
OndraFiedler committed Aug 13, 2021
2 parents 0c2f2b0 + 13819c2 commit 9ea2b6c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/RecommApi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Client for easy usage of Recombee recommendation API
*/
class Client{

protected $account;
protected $token;
protected $request;
Expand Down Expand Up @@ -72,7 +72,7 @@ protected function getUserAgent() {
* @throws Exceptions\ApiTimeoutException ApiTimeoutException if the request takes too long
*/
public function send(Requests\Request $request) {

if($request instanceof Requests\Batch && count($request->requests) > Client::BATCH_MAX_SIZE)
return $this->sendMultipartBatch($request);

Expand Down Expand Up @@ -108,12 +108,12 @@ public function send(Requests\Request $request) {
}
catch(\GuzzleHttp\Exception\ConnectException $e)
{
throw new ApiTimeoutException($request);
throw new ApiTimeoutException($request, $e);
}
catch(\GuzzleHttp\Exception\GuzzleException $e)
{
if(strpos($e->getMessage(), 'cURL error 28') !== false) throw new ApiTimeoutException($request);
if(strpos($e->getMessage(), 'timed out') !== false) throw new ApiTimeoutException($request);
if(strpos($e->getMessage(), 'cURL error 28') !== false) throw new ApiTimeoutException($request, $e);
if(strpos($e->getMessage(), 'timed out') !== false) throw new ApiTimeoutException($request, $e);

throw $e;
}
Expand All @@ -129,7 +129,7 @@ protected function getOptionalHttpHeaders() {
}

protected function getHttpHeaders() {
return array_merge(array('User-Agent' => $this->user_agent), $this->getOptionalHttpHeaders());
return array_merge(array('User-Agent' => $this->user_agent), $this->getOptionalHttpHeaders());
}

protected function getRequestOptions() {
Expand Down
2 changes: 1 addition & 1 deletion src/RecommApi/Exceptions/ApiTimeoutException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApiTimeoutException extends ApiException{
*/
public $request;

public function __construct($request, Exception $previous = null) {
public function __construct($request, \Exception $previous = null) {
$this->request = $request;
$description = "Client did not get response within #{$request->getTimeout()} ms";
parent::__construct($description, 28, $previous);
Expand Down
2 changes: 1 addition & 1 deletion src/RecommApi/Exceptions/ResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ResponseException extends ApiException{
*/
public $description;

public function __construct($request, $status_code, $description, Exception $previous = null) {
public function __construct($request, $status_code, $description, \Exception $previous = null) {
$this->request = $request;
$this->status_code = $status_code;
$this->description = $description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class UnknownOptionalParameterException extends \InvalidArgumentException {

/**
* @var string $parameter Given invalid name
*/
*/
public $parameter;

public function __construct($par, Exception $previous = null) {
public function __construct($par, \Exception $previous = null) {
$this->parameter = $par;
parent::__construct("Unknown parameter {$this->parameter} was given to the request", 0, $previous);
}
Expand Down

0 comments on commit 9ea2b6c

Please sign in to comment.