Skip to content

Commit 652a67f

Browse files
authored
Merge pull request #133 from elzozo13/master
Added last http code as exception code
2 parents 0e1c69c + 5eb1e32 commit 652a67f

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

lib/GraphQL.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
namespace PHPShopify;
1212

1313

14+
use PHPShopify\Exception\ApiException;
15+
use PHPShopify\Exception\CurlException;
1416
use PHPShopify\Exception\SdkException;
1517

1618
class GraphQL extends ShopifyResource
@@ -33,6 +35,8 @@ protected function getResourcePath()
3335
* @param array|null $variables
3436
*
3537
* @uses HttpRequestGraphQL::post() to send the HTTP request
38+
* @throws ApiException if the response has an error specified
39+
* @throws CurlException if response received with unexpected HTTP code.
3640
*
3741
* @return array
3842
*/
@@ -47,6 +51,7 @@ public function post($graphQL, $url = null, $wrapData = false, $variables = null
4751

4852
/**
4953
* @inheritdoc
54+
* @throws SdkException
5055
*/
5156
public function get($urlParams = array(), $url = null, $dataKey = null)
5257
{
@@ -55,6 +60,7 @@ public function get($urlParams = array(), $url = null, $dataKey = null)
5560

5661
/**
5762
* @inheritdoc
63+
* @throws SdkException
5864
*/
5965
public function put($dataArray, $url = null, $wrapData = true)
6066
{
@@ -63,6 +69,7 @@ public function put($dataArray, $url = null, $wrapData = true)
6369

6470
/**
6571
* @inheritdoc
72+
* @throws SdkException
6673
*/
6774
public function delete($urlParams = array(), $url = null)
6875
{

lib/HttpRequestJson.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected static function prepareRequest($httpHeaders = array(), $dataArray = ar
6262
* @param string $url
6363
* @param array $httpHeaders
6464
*
65-
* @return string
65+
* @return array
6666
*/
6767
public static function get($url, $httpHeaders = array())
6868
{
@@ -80,7 +80,7 @@ public static function get($url, $httpHeaders = array())
8080
* @param array $dataArray
8181
* @param array $httpHeaders
8282
*
83-
* @return string
83+
* @return array
8484
*/
8585
public static function post($url, $dataArray, $httpHeaders = array())
8686
{
@@ -98,7 +98,7 @@ public static function post($url, $dataArray, $httpHeaders = array())
9898
* @param array $dataArray
9999
* @param array $httpHeaders
100100
*
101-
* @return string
101+
* @return array
102102
*/
103103
public static function put($url, $dataArray, $httpHeaders = array())
104104
{
@@ -115,7 +115,7 @@ public static function put($url, $dataArray, $httpHeaders = array())
115115
* @param string $url
116116
* @param array $httpHeaders
117117
*
118-
* @return string
118+
* @return array
119119
*/
120120
public static function delete($url, $httpHeaders = array())
121121
{

lib/ShopifyResource.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ public function generateUrl($urlParams = array(), $customAction = null)
302302
*
303303
* @uses HttpRequestJson::get() to send the HTTP request
304304
*
305+
* @throws ApiException if the response has an error specified
306+
* @throws CurlException if response received with unexpected HTTP code.
307+
*
305308
* @return array
306309
*/
307310
public function get($urlParams = array(), $url = null, $dataKey = null)
@@ -321,6 +324,10 @@ public function get($urlParams = array(), $url = null, $dataKey = null)
321324
*
322325
* @param array $urlParams Check Shopify API reference of the specific resource for the list of URL parameters
323326
*
327+
* @throws SdkException
328+
* @throws ApiException if the response has an error specified
329+
* @throws CurlException if response received with unexpected HTTP code.
330+
*
324331
* @return integer
325332
*/
326333
public function count($urlParams = array())
@@ -340,6 +347,8 @@ public function count($urlParams = array())
340347
* @param mixed $query
341348
*
342349
* @throws SdkException if search is not enabled for the resouce
350+
* @throws ApiException if the response has an error specified
351+
* @throws CurlException if response received with unexpected HTTP code.
343352
*
344353
* @return array
345354
*/
@@ -365,6 +374,9 @@ public function search($query)
365374
*
366375
* @uses HttpRequestJson::post() to send the HTTP request
367376
*
377+
* @throws ApiException if the response has an error specified
378+
* @throws CurlException if response received with unexpected HTTP code.
379+
*
368380
* @return array
369381
*/
370382
public function post($dataArray, $url = null, $wrapData = true)
@@ -387,6 +399,9 @@ public function post($dataArray, $url = null, $wrapData = true)
387399
*
388400
* @uses HttpRequestJson::put() to send the HTTP request
389401
*
402+
* @throws ApiException if the response has an error specified
403+
* @throws CurlException if response received with unexpected HTTP code.
404+
*
390405
* @return array
391406
*/
392407
public function put($dataArray, $url = null, $wrapData = true)
@@ -409,6 +424,9 @@ public function put($dataArray, $url = null, $wrapData = true)
409424
*
410425
* @uses HttpRequestJson::delete() to send the HTTP request
411426
*
427+
* @throws ApiException if the response has an error specified
428+
* @throws CurlException if response received with unexpected HTTP code.
429+
*
412430
* @return array an empty array will be returned if the request is successfully completed
413431
*/
414432
public function delete($urlParams = array(), $url = null)
@@ -493,7 +511,7 @@ public function processResponse($responseArray, $dataKey = null)
493511
if (isset($responseArray['errors'])) {
494512
$message = $this->castString($responseArray['errors']);
495513

496-
throw new ApiException($message);
514+
throw new ApiException($message, CurlRequest::$lastHttpCode);
497515
}
498516

499517
if ($dataKey && isset($responseArray[$dataKey])) {

0 commit comments

Comments
 (0)