slince / shopify-api-php

:rocket: Shopify API Client for PHP
MIT License
128 stars 47 forks source link

Exception when trying to throw ClientException #95

Closed animkaTT closed 3 years ago

animkaTT commented 3 years ago

If the data is not correct when creating something, then from Shopify we can get an array in "errors", not a string. For example, if you create a webhook whose topic does not exist (test/update) Request:

POST https://{{shop}}/admin/api/2020-07/webhooks.json
X-Shopify-Access-Token: {{accessToken}}
Content-Type: application/json
{
  "webhook": {
    "topic": "test/update",
    "address": "https://test.test/webhooks/test/update",
    "format": "json"
  }
}

Response code: 422 (Unprocessable Entity);

Response body:

{
  "errors": {
    "topic": [
      "Invalid topic specified: test\/update. Topics allowed: app\/uninstalled, carts\/create, carts\/update, checkouts\/create, checkouts\/delete, checkouts\/update, collections\/create, collections\/delete, collections\/update, customer_groups\/create, customer_groups\/delete, customer_groups\/update, customers\/create, customers\/delete, customers\/disable, customers\/enable, customers\/update, order_transactions\/create, orders\/cancelled, orders\/create, orders\/delete, orders\/edited, orders\/fulfilled, orders\/paid, orders\/partially_fulfilled, orders\/updated, products\/create, products\/delete, products\/update, refunds\/create, shop\/update, inventory_levels\/connect, inventory_levels\/update, inventory_levels\/disconnect, inventory_items\/create, inventory_items\/update, inventory_items\/delete, tender_transactions\/create, app_purchases_one_time\/update, app_subscriptions\/update, domains\/create, domains\/update, domains\/destroy"
    ]
  }
}

If create this webhook with slince/shopify-api-php, we get Symfony\Component\Debug\Exception\FatalThrowableError with a message "Wrong parameters for Slince\Shopify\Exception\UnprocessableEntityException([string $message [, long $code [, Throwable $previous = NULL]]])" in ClientException.php#L37

slince commented 3 years ago

tks

slince commented 3 years ago

fixed in 3.0.0