When using WordPress HTTP API, if the connection fails you could use the below code to display the error message.
$response = wp_remote_post($url); | |
if (is_wp_error($response)) { | |
$error = $response->get_error_message(); | |
echo $error; | |
} else { | |
$content = wp_remote_retrieve_body($response); | |
} |
Both wp_remote_post and wp_remote_get return WP_Error object if there is an error. You could use the get_error_message function of WP_Error class to receive the error and show it.