Skip to content

Commit 3fd6060

Browse files
authored
Merge pull request #8 from wp-cli/7-error-msg
Properly handle WP_Error object returned by `wp_remote_head()`
2 parents 2f67a04 + cb6e571 commit 3fd6060

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,14 @@ protected static function alter_api_response( $response, $version ) {
248248
$response = wp_remote_head( $response->download_link );
249249
$response_code = wp_remote_retrieve_response_code( $response );
250250
if ( 200 !== $response_code ) {
251+
if ( is_wp_error( $response ) ) {
252+
$error_msg = $response->get_error_message();
253+
} else {
254+
$error_msg = sprintf( 'HTTP code %d', $response_code );
255+
}
251256
\WP_CLI::error( sprintf(
252-
"Can't find the requested %s's version %s in the WordPress.org %s repository (HTTP code %d).",
253-
$download_type, $version, $download_type, $response_code ) );
257+
"Can't find the requested %s's version %s in the WordPress.org %s repository (%s).",
258+
$download_type, $version, $download_type, $error_msg ) );
254259
}
255260
}
256261
}

0 commit comments

Comments
 (0)