bold-commerce / go-shopify

Go client for the Shopify API
MIT License
328 stars 255 forks source link

wrapSpecificError function does not handle 429 status code correctly #206

Closed ching-xia closed 1 year ago

ching-xia commented 1 year ago

Description

There is a bug in the goshopify.go file, line 431, function wrapSpecificError. When the shop reaches the limit of creating products every day, the response error status is 429 (Too Many Requests), but retrying the request will not help.

Steps to reproduce

  1. Connect to a shop with goshopify and set up authentication.
  2. Create products using the ProductService.Create method until the shop reaches the daily limit.
  3. Observe the error returned by the ProductService.Create method and inspect its type and fields.

More Info:

responseError Status: 429 responseError Message: "product: Daily variant creation limit reached. Please try again later. See https://help.shopify.com/api/getting-started/api-call-limit for more information about rate limits and how to avoid them."

Shopify API Limit Doc

Resource-based rate limitsAnchor link to section titled "Resource-based rate limits"

The following Admin API resources, in both GraphQL and REST versions, have an additional throttle that takes effect when a store has 50,000 product variants. After this threshold is reached, no more than 1,000 new variants can be created per day.

In certain cases, Shopify needs to enforce rate limiting in order to prevent abuse of the platform. Therefore, your app should be prepared to handle rate limiting on all endpoints, rather than just those listed here.

oliver006 commented 1 year ago

IMO 429 seems like an appropriate error in this case, and retrying makes sense to me. The client is not aware of when the rate limit resets so retrying is not a terrible idea (after all, it might reset within the next few seconds and subsequently, the request succeeds).

What do you think should be the behavior of the client in the scenario you described?