klaviyo / php-klaviyo

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

400 responses cause spurious PHP notices if response was blank #57

Closed bradleymellen closed 3 years ago

bradleymellen commented 3 years ago

I'm encountering an issue when Klaviyo returns a 400 (Bad Request) but does not provide any response body. The change from issue #40 assumes that the response contains some details and tries to provide them, but since the response is empty, it causes a PHP notice since it's looking for a "detail" element that doesn't exist:

Notice: Undefined index: detail in Klaviyo\KlaviyoAPI->handleResponse() (line 185 of /var/www/www.highlights.com/webroot/sites/www.highlights.com/modules/hfc_comm_pref/vendor/klaviyo/php-sdk/src/KlaviyoAPI.php).

This happens, for instance, when I attempt to check whether a profile belongs to a list, but the list ID I passed is invalid. Of course the obvious response in this case might be "so don't pass invalid list IDs", but given that there exists any situation where Klaviyo might choose to reply with an empty 400 response, it would be nice if handleResponse was prepared for that situation and didn't clutter the logs with PHP notices.

smoucka commented 3 years ago

Thanks for bringing this up @bradleymellen . Taking a look at your PR now.

smoucka commented 3 years ago

Merged #58