Merge branch 'image-upload-error-messages'

This commit is contained in:
Mike Jolley 2016-06-20 10:54:30 +01:00
commit 7263ec126e
4 changed files with 13 additions and 5 deletions

View File

@ -1797,7 +1797,9 @@ class WC_API_Products extends WC_API_Resource {
'timeout' => 10
) );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
if ( is_wp_error( $response ) ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_remote_product_image', sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url . ': ' . $response->get_error_message() ), 400 );
} elseif ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_remote_product_image', sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url ), 400 );
}

View File

@ -2353,7 +2353,9 @@ class WC_API_Products extends WC_API_Resource {
'timeout' => 10
) );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
if ( is_wp_error( $response ) ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_remote_' . $upload_for, sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url . ': ' . $response->get_error_message() ), 400 );
} elseif ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_remote_' . $upload_for, sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url ), 400 );
}

View File

@ -2018,7 +2018,9 @@ class WC_CLI_Product extends WC_CLI_Command {
'timeout' => 10
) );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
if ( is_wp_error( $response ) ) {
throw new WC_CLI_Exception( 'woocommerce_cli_invalid_remote_product_image', sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url . ': ' . $response->get_error_message() ) );
} elseif ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
throw new WC_CLI_Exception( 'woocommerce_cli_invalid_remote_product_image', sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url ) );
}

View File

@ -64,8 +64,10 @@ function wc_rest_upload_image_from_url( $image_url ) {
'timeout' => 10
) );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
return new WP_Error( 'woocommerce_rest_invalid_remote_image_url', sprintf( __( 'Error getting remote image %s.', 'woocommerce' ), $image_url ), array( 'status' => 400 ) );
if ( is_wp_error( $response ) ) {
return new WP_Error( 'woocommerce_rest_invalid_remote_image_url', sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url . ': ' . $response->get_error_message() ), array( 'status' => 400 ) );
} elseif ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
return new WP_Error( 'woocommerce_rest_invalid_remote_image_url', sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url ), array( 'status' => 400 ) );
}
// Ensure we have a file name and type.