When using WordPress HTTP API, if the connection fails you could use the below code to display the error message.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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.