From 5b1fe8a6595b439751c45ca53dbef7cb482bc9b7 Mon Sep 17 00:00:00 2001 From: Petrescu Victor Date: Wed, 22 Jan 2020 16:02:02 +0200 Subject: [PATCH 1/3] Added last http code as exception code --- lib/ShopifyResource.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index e8f6542..9eb905e 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -492,8 +492,8 @@ public function processResponse($responseArray, $dataKey = null) if (isset($responseArray['errors'])) { $message = $this->castString($responseArray['errors']); - - throw new ApiException($message); +z + throw new ApiException($message, CurlRequest::$lastHttpCode); } if ($dataKey && isset($responseArray[$dataKey])) { From 9ca83e48774531b9fdecc71b4e0c1476b9c2f0f3 Mon Sep 17 00:00:00 2001 From: Petrescu Victor Date: Wed, 22 Jan 2020 19:47:24 +0200 Subject: [PATCH 2/3] Removed misstype --- lib/ShopifyResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 9eb905e..8ef9cff 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -492,7 +492,7 @@ public function processResponse($responseArray, $dataKey = null) if (isset($responseArray['errors'])) { $message = $this->castString($responseArray['errors']); -z + throw new ApiException($message, CurlRequest::$lastHttpCode); } From 5eb1e32846351c40f7e5f53a959a761007df54da Mon Sep 17 00:00:00 2001 From: Petrescu Victor Date: Wed, 29 Jan 2020 17:45:31 +0200 Subject: [PATCH 3/3] Fixed docs --- lib/GraphQL.php | 7 +++++++ lib/HttpRequestJson.php | 8 ++++---- lib/ShopifyResource.php | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/GraphQL.php b/lib/GraphQL.php index 7d49d25..185593b 100644 --- a/lib/GraphQL.php +++ b/lib/GraphQL.php @@ -11,6 +11,8 @@ namespace PHPShopify; +use PHPShopify\Exception\ApiException; +use PHPShopify\Exception\CurlException; use PHPShopify\Exception\SdkException; class GraphQL extends ShopifyResource @@ -33,6 +35,8 @@ protected function getResourcePath() * @param array|null $variables * * @uses HttpRequestGraphQL::post() to send the HTTP request + * @throws ApiException if the response has an error specified + * @throws CurlException if response received with unexpected HTTP code. * * @return array */ @@ -47,6 +51,7 @@ public function post($graphQL, $url = null, $wrapData = false, $variables = null /** * @inheritdoc + * @throws SdkException */ public function get($urlParams = array(), $url = null, $dataKey = null) { @@ -55,6 +60,7 @@ public function get($urlParams = array(), $url = null, $dataKey = null) /** * @inheritdoc + * @throws SdkException */ public function put($dataArray, $url = null, $wrapData = true) { @@ -63,6 +69,7 @@ public function put($dataArray, $url = null, $wrapData = true) /** * @inheritdoc + * @throws SdkException */ public function delete($urlParams = array(), $url = null) { diff --git a/lib/HttpRequestJson.php b/lib/HttpRequestJson.php index ee8372a..ceab78f 100644 --- a/lib/HttpRequestJson.php +++ b/lib/HttpRequestJson.php @@ -62,7 +62,7 @@ protected static function prepareRequest($httpHeaders = array(), $dataArray = ar * @param string $url * @param array $httpHeaders * - * @return string + * @return array */ public static function get($url, $httpHeaders = array()) { @@ -80,7 +80,7 @@ public static function get($url, $httpHeaders = array()) * @param array $dataArray * @param array $httpHeaders * - * @return string + * @return array */ public static function post($url, $dataArray, $httpHeaders = array()) { @@ -98,7 +98,7 @@ public static function post($url, $dataArray, $httpHeaders = array()) * @param array $dataArray * @param array $httpHeaders * - * @return string + * @return array */ public static function put($url, $dataArray, $httpHeaders = array()) { @@ -115,7 +115,7 @@ public static function put($url, $dataArray, $httpHeaders = array()) * @param string $url * @param array $httpHeaders * - * @return string + * @return array */ public static function delete($url, $httpHeaders = array()) { diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 8ef9cff..8d7be10 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -302,6 +302,9 @@ public function generateUrl($urlParams = array(), $customAction = null) * * @uses HttpRequestJson::get() to send the HTTP request * + * @throws ApiException if the response has an error specified + * @throws CurlException if response received with unexpected HTTP code. + * * @return array */ public function get($urlParams = array(), $url = null, $dataKey = null) @@ -321,6 +324,10 @@ public function get($urlParams = array(), $url = null, $dataKey = null) * * @param array $urlParams Check Shopify API reference of the specific resource for the list of URL parameters * + * @throws SdkException + * @throws ApiException if the response has an error specified + * @throws CurlException if response received with unexpected HTTP code. + * * @return integer */ public function count($urlParams = array()) @@ -340,6 +347,8 @@ public function count($urlParams = array()) * @param mixed $query * * @throws SdkException if search is not enabled for the resouce + * @throws ApiException if the response has an error specified + * @throws CurlException if response received with unexpected HTTP code. * * @return array */ @@ -365,6 +374,9 @@ public function search($query) * * @uses HttpRequestJson::post() to send the HTTP request * + * @throws ApiException if the response has an error specified + * @throws CurlException if response received with unexpected HTTP code. + * * @return array */ public function post($dataArray, $url = null, $wrapData = true) @@ -387,6 +399,9 @@ public function post($dataArray, $url = null, $wrapData = true) * * @uses HttpRequestJson::put() to send the HTTP request * + * @throws ApiException if the response has an error specified + * @throws CurlException if response received with unexpected HTTP code. + * * @return array */ public function put($dataArray, $url = null, $wrapData = true) @@ -409,6 +424,9 @@ public function put($dataArray, $url = null, $wrapData = true) * * @uses HttpRequestJson::delete() to send the HTTP request * + * @throws ApiException if the response has an error specified + * @throws CurlException if response received with unexpected HTTP code. + * * @return array an empty array will be returned if the request is successfully completed */ public function delete($urlParams = array(), $url = null)