Skip to content

Commit

Permalink
Handle Shopify api exception
Browse files Browse the repository at this point in the history
  • Loading branch information
shopifychamp committed Dec 29, 2020
1 parent abd3cf2 commit 32ac7cf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ public function callGraphql($query)
if(isset($response['errors']))
{
$http_bad_request_code = 400;
throw new ApiException(\GuzzleHttp\json_encode($response['errors']),$http_bad_request_code);

$error_message = $response['errors'];
if(is_array($response['errors']))
$error_message = json_encode($response['errors']);

throw new ApiException($error_message,$http_bad_request_code);
}
return $response;
}
Expand Down Expand Up @@ -245,6 +250,10 @@ public function request($method,$url,array $options)
else {
$error_message = $e->getMessage();
}

if(is_array($error_message))
$error_message = json_encode($error_message);

throw new ApiException($error_message,$e->getCode());
}
}
Expand Down Expand Up @@ -506,4 +515,4 @@ public function setApiParams($api_params){
public function getApiParams(){
return $this->api_params;
}
}
}

0 comments on commit 32ac7cf

Please sign in to comment.