dirkgroenen / pinterest-api-php

A PHP wrapper for the official Pinterest API. :pushpin:
https://developers.pinterest.com/docs/getting-started/introduction/
Apache License 2.0
173 stars 76 forks source link

Should have different error for empty response than error response #45

Closed smvanbru closed 8 years ago

smvanbru commented 8 years ago

At present, in Pinterest/Transport/Request.php, line 211-212, you raise an error for empty response with the same block of code as an error response. With that setup, the empty response is hard to identify in order to be handled appropriately in apps using this library. Would it be possible to adjust this bit to return an identifiable error code for empty responses? Thanks!

dirkgroenen commented 8 years ago

I assume you're referring to the difference between a FALSE response from curl_exec compared to a curl_exec which returns with curl errors? In case you mean something like that I assume something like the following would help:

if ($response_data === false && !$ch->hasErrors()) {
    throw new CurlException("Error: Curl request failed")
}
else if($ch->hasErrors()) {
    throw new PinterestException('Error: execute() - cURL error: ' . $ch->getErrors(), $ch->getErrorNumber());
}

Let me know if the above is what you mean.

smvanbru commented 8 years ago

ya, that should do it. Thanks!

dirkgroenen commented 8 years ago

Cool, I've merged the changes into development. Shall be merged into master somewhere in the next few days.

dirkgroenen commented 8 years ago

Just released a new version which includes this fix.