Added last http code as exception code #133
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Shopify has a really good policy regarding errors and error codes described here: https://help.shopify.com/en/api/getting-started/response-status-codes (Pretty sure some of the contributors read it since 429 is mentioned in code).
The problem is that the errors ar thrown without the code. That in turn forces ppl to keep using stuff like stripos($response, '[API] Invalid API key or access token') to be able to catch exceptions and treat them. This is results in unnecessary maintenance (especially if for some reason shopify decide to change a message text). Another option would be to call the CurlRequest::$lastHttpCode from outside the php-shopify code, but that would couple the lib into the project and I don't think I need to mention why that is bad :).
I added the last http response code as an error code.
Also (I didn't treat this here but it is a problem), having the $lastHttpCode as static on curl may result in resource races with wrong outcome (unless I'm missing someting here? don't think so but hope so). I plan on adding an issue with that if that's ok with you, and making another pull request to resolve that.