Performance indicators - bail whenever an internal API request fails.

This commit is contained in:
Jeff Stieler 2019-06-11 14:10:38 -06:00
parent ddbb8f0be8
commit 1825c30b26
1 changed files with 20 additions and 5 deletions

View File

@ -119,16 +119,27 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re
$request = new WP_REST_Request( 'GET', '/wc/v4/reports' );
$response = rest_do_request( $request );
$endpoints = $response->get_data();
$allowed_stats = array();
if ( is_wp_error( $response ) ) {
return $response;
}
if ( 200 !== $response->get_status() ) {
return new WP_Error( 'woocommerce_reports_performance_indicators_result_failed', __( 'Sorry, fetching performance indicators failed.', 'woocommerce-admin' ) );
}
$endpoints = $response->get_data();
$allowed_stats = array();
foreach ( $endpoints as $endpoint ) {
if ( '/stats' === substr( $endpoint['slug'], -6 ) ) {
$request = new WP_REST_Request( 'OPTIONS', $endpoint['path'] );
$response = rest_do_request( $request );
if ( is_wp_error( $response ) ) {
return $response;
}
$data = $response->get_data();
$prefix = substr( $endpoint['slug'], 0, -6 );
@ -283,6 +294,10 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re
$response = rest_do_request( $request );
if ( is_wp_error( $response ) ) {
return $response;
}
$data = $response->get_data();
$format = $this->formats[ $stat ];
$label = $this->labels[ $stat ];