markjaquith / feedback

Ask @markjaquith anything!
42 stars 4 forks source link

How to thoroughly test wp_remote_get() return #39

Closed MickeyKay closed 8 years ago

MickeyKay commented 9 years ago

Hi there,

I've been using wp_remote_get() in a recent project and have been trying to refine the process by which I process the returned response. Specifically, I'd like to know the best way to check the call was successful and returned some valid content. I've seen various test conditionals, however none of them seem to fully work. Amongst several possible return values I need to test for are:

I would love to see a comprehensive set of conditionals that checks to make sure the remote fetch connected and returned valid, useful data. Any ideas? Thanks!

afragen commented 9 years ago

Hey Mickey,

While certainly not exhaustive, I use the following in some code, https://github.com/afragen/github-updater/blob/develop/includes/class-github-api.php#L88L100

markjaquith commented 8 years ago

First, check against WP_Error. Next, check the data returned. Or use the response code to indicate various error situations.