Added more informative error messages when API request fails on the in-app marketplace featured page.
This commit is contained in:
parent
9a0e91477e
commit
61d46c6987
|
@ -89,7 +89,13 @@ class WC_Admin_Addons {
|
||||||
|
|
||||||
if ( is_wp_error( $raw_featured ) ) {
|
if ( is_wp_error( $raw_featured ) ) {
|
||||||
do_action( 'woocommerce_page_wc-addons_connection_error', $raw_featured->get_error_message() );
|
do_action( 'woocommerce_page_wc-addons_connection_error', $raw_featured->get_error_message() );
|
||||||
self::output_empty();
|
|
||||||
|
$message = null;
|
||||||
|
if ( self::is_ssl_error( $raw_featured->get_error_message() ) ) {
|
||||||
|
$message = __( 'We encountered an SSL error. Please check if your site supports TLS version 1.2 or above.', 'woocommerce' );
|
||||||
|
}
|
||||||
|
|
||||||
|
self::output_empty( $message );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +103,19 @@ class WC_Admin_Addons {
|
||||||
$response_code = intval( wp_remote_retrieve_response_code( $raw_featured ) );
|
$response_code = intval( wp_remote_retrieve_response_code( $raw_featured ) );
|
||||||
if ( 200 !== $response_code ) {
|
if ( 200 !== $response_code ) {
|
||||||
do_action( 'woocommerce_page_wc-addons_connection_error', $response_code );
|
do_action( 'woocommerce_page_wc-addons_connection_error', $response_code );
|
||||||
self::output_empty();
|
|
||||||
|
/* translators: %d: HTTP error code. */
|
||||||
|
$message = sprintf(
|
||||||
|
esc_html(
|
||||||
|
__(
|
||||||
|
'Error code %d.',
|
||||||
|
'woocommerce'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
$response_code
|
||||||
|
);
|
||||||
|
|
||||||
|
self::output_empty( $message );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +123,8 @@ class WC_Admin_Addons {
|
||||||
$featured = json_decode( wp_remote_retrieve_body( $raw_featured ) );
|
$featured = json_decode( wp_remote_retrieve_body( $raw_featured ) );
|
||||||
if ( empty( $featured ) || ! is_array( $featured ) ) {
|
if ( empty( $featured ) || ! is_array( $featured ) ) {
|
||||||
do_action( 'woocommerce_page_wc-addons_connection_error', 'Empty or malformed response' );
|
do_action( 'woocommerce_page_wc-addons_connection_error', 'Empty or malformed response' );
|
||||||
self::output_empty();
|
$message = __( 'We received an empty or malformed response', 'woocommerce' );
|
||||||
|
self::output_empty( $message );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -118,6 +137,10 @@ class WC_Admin_Addons {
|
||||||
self::output_featured( $featured );
|
self::output_featured( $featured );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function is_ssl_error( $error_message ) {
|
||||||
|
return ( false !== stripos( $error_message, 'cURL error 35' ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build url parameter string
|
* Build url parameter string
|
||||||
*
|
*
|
||||||
|
@ -941,25 +964,28 @@ class WC_Admin_Addons {
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function output_empty() {
|
public static function output_empty( $message = '' ) {
|
||||||
?>
|
?>
|
||||||
<div class="wc-addons__empty">
|
<div class="wc-addons__empty">
|
||||||
<h2><?php echo wp_kses_post( __( 'Sorry, we\'re having trouble connecting to the extensions catalog.', 'woocommerce' ) ); ?></h2>
|
<h2><?php echo wp_kses_post( __( 'Sorry, we\'re having trouble connecting to the extensions catalog.', 'woocommerce' ) ); ?></h2>
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
/* translators: a url */
|
/* translators: a url */
|
||||||
printf(
|
printf(
|
||||||
wp_kses_post(
|
wp_kses_post(
|
||||||
__(
|
__(
|
||||||
'Head over to <a href="%s">WooCommerce.com</a> to start growing your business with the most popular WooCommerce extensions.',
|
'Head over to <a href="%s">WooCommerce.com</a> to start growing your business with the most popular WooCommerce extensions.',
|
||||||
'woocommerce'
|
'woocommerce'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'https://woocommerce.com/products/?utm_source=extensionsscreen&utm_medium=product&utm_campaign=connectionerror'
|
'https://woocommerce.com/products/?utm_source=extensionsscreen&utm_medium=product&utm_campaign=connectionerror'
|
||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
<?php if ( ! empty( $message ) ) : ?>
|
||||||
|
<p><?php echo esc_html( $message ); ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue