Skip to content

Commit

Permalink
update exception
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejregula committed Oct 10, 2022
1 parent edd3b44 commit 7935468
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions shopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,22 @@ function _shop_api_call_limit_param($index, $response_headers)
}


class Exception extends http\Exception { }
class CurlException extends Exception { }
class ApiException extends Exception
{
function __construct($message, $code, $request, $response=array(), Exception $previous=null)
{
$response_body_json = isset($response['body']) ? $response['body'] : '';
$response = json_decode($response_body_json, true);
$response_error = isset($response['errors']) ? ' '.var_export($response['errors'], true) : '';
$this->message = $message.$response_error;
parent::__construct($this->message, $code, $request, $response, $previous);
}
}
class Exception extends http\Exception { }
class CurlException extends Exception { }
class ApiException extends Exception
{
function __construct($message, $code, $request, $response=array(), Exception $previous=null)
{
$response_body_json = isset($response['body']) ? $response['body'] : '';
if (is_array($response_body_json) && isset($response_body_json['errors'])) {
parent::__construct(var_export($response_body_json['errors'], true), 200, $request);
} else {
$response = json_decode($response_body_json, true);
$response_error = isset($response['errors']) ? ' '.var_export($response['errors'], true) : '';
$this->message = $message.$response_error;
parent::__construct($this->message, $code, $request, $response, $previous);
}
}
}

?>

0 comments on commit 7935468

Please sign in to comment.