Skip to content

Added last http code as exception code #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace PHPShopify;


use PHPShopify\Exception\ApiException;
use PHPShopify\Exception\CurlException;
use PHPShopify\Exception\SdkException;

class GraphQL extends ShopifyResource
Expand All @@ -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
*/
Expand All @@ -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)
{
Expand All @@ -55,6 +60,7 @@ public function get($urlParams = array(), $url = null, $dataKey = null)

/**
* @inheritdoc
* @throws SdkException
*/
public function put($dataArray, $url = null, $wrapData = true)
{
Expand All @@ -63,6 +69,7 @@ public function put($dataArray, $url = null, $wrapData = true)

/**
* @inheritdoc
* @throws SdkException
*/
public function delete($urlParams = array(), $url = null)
{
Expand Down
8 changes: 4 additions & 4 deletions lib/HttpRequestJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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())
{
Expand All @@ -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())
{
Expand All @@ -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())
{
Expand Down
20 changes: 19 additions & 1 deletion lib/ShopifyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -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
*/
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -493,7 +511,7 @@ public function processResponse($responseArray, $dataKey = null)
if (isset($responseArray['errors'])) {
$message = $this->castString($responseArray['errors']);

throw new ApiException($message);
throw new ApiException($message, CurlRequest::$lastHttpCode);
}

if ($dataKey && isset($responseArray[$dataKey])) {
Expand Down