Skip to content

Commit

Permalink
Version 0.1.1
Browse files Browse the repository at this point in the history
* Add API error response heandler
  • Loading branch information
lar-dragon authored Aug 14, 2019
1 parent ad1b72e commit 2a2ff40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "qiwi/bill-payments-php-sdk",
"type": "library",
"version": "0.1.0",
"version": "0.1.1",
"description": "Universal payments API SDK",
"license": "MIT",
"homepage": "https://github.com/QIWI-API/bill-payments-php-sdk",
Expand Down
24 changes: 22 additions & 2 deletions src/BillPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,31 @@ protected function requestBuilder($uri, $method=self::GET, array $body=[])
}

if (true === $this->internalCurl->error) {
throw new BillPaymentsException(clone $this->internalCurl);
throw new BillPaymentsException(
clone $this->internalCurl,
$this->internalCurl->error_message,
$this->internalCurl->error_code
);
}

if (false === empty($this->internalCurl->response)) {
return @json_decode($this->internalCurl->response, true);
$json = json_decode($this->internalCurl->response, true);
if (is_null($json)) {
throw new BillPaymentsException(
clone $this->internalCurl,
json_last_error_msg(),
json_last_error()
);
}

if (isset($json['errorCode'])) {
throw new BillPaymentsException(
clone $this->internalCurl,
isset($json['description']) ? $json['description'] : $json['errorCode']
);
}

return $json;
}

return true;
Expand Down

0 comments on commit 2a2ff40

Please sign in to comment.