With your code you assume to have a WiFi network available otherwise that will again block indefinetly.
And in order to check if you can reach the internet once you got a WiFi.ready()
you can always use WiFi.ping()
and/or WiFi.resolve()
or any other way to request data from the net.
But for OTA updates, you need a valid Particle cloud connection.