klaviyo / php-klaviyo

PHP wrapper for the Klaviyo API
59 stars 47 forks source link

Handle empty response when json_decoding #30

Closed kamil-klasicki closed 3 years ago

kamil-klasicki commented 3 years ago

There are cases where our API returns to us an empty response (Unsubscribe from List being an example). Any php version > 7 will throw a JSON_ERROR_SYNTAX (4) If an empty string is passed. To solve the issue, we should check if the response is empty. If it is, instead of decoding the response we should decode an empty object. To keep the function consistent, I've added true as the second argument to return an empty array.

The logic has been tested on php 7.3 I've attached 2 screenshots showing int(4) being returned currently, and 0 (no error) after the update.

Screenshot 2020-10-06 at 10 52 07 Screenshot 2020-10-06 at 10 50 25