Skip to content

Commit 3624a2c

Browse files
committed
Edit API client error message wording for syntax and redundancy
1 parent 3969630 commit 3624a2c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

classes/class-wc-connect-api-client.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,12 @@ protected function request( $method, $path, $body = array() ) {
372372
// If the received response is not JSON, return the raw response
373373
$content_type = wp_remote_retrieve_header( $response, 'content-type' );
374374
if ( false === strpos( $content_type, 'application/json' ) ) {
375-
if ( 200 != $response_code ) {
376-
return new WP_Error(
377-
'wcc_server_error',
378-
sprintf( 'Error: The WooCommerce Services server returned HTTP code: %d', $response_code )
379-
);
375+
if ( ! $response_code ) {
376+
return new WP_Error( 'wcc_server_error', 'The WooCommerce Services API could not be reached. Please make sure your server can make requests to api.woocommerce.com, and try again.' );
377+
} elseif ( 500 == $response_code ) {
378+
return new WP_Error( 'wcc_server_error', 'The WooCommerce Services API encountered an error. Please try again.' );
379+
} elseif ( 200 != $response_code ) {
380+
return new WP_Error( 'wcc_server_error', sprintf( 'The WooCommerce Services API returned HTTP status code: %d', $response_code ) );
380381
}
381382
return $response;
382383
}
@@ -391,7 +392,7 @@ protected function request( $method, $path, $body = array() ) {
391392
return new WP_Error(
392393
'wcc_server_empty_response',
393394
sprintf(
394-
'Error: The WooCommerce Services server returned ( %d ) and an empty response body.',
395+
'The WooCommerce Services API returned HTTP status code %d and an empty response body.',
395396
$response_code
396397
)
397398
);
@@ -401,13 +402,17 @@ protected function request( $method, $path, $body = array() ) {
401402
$message = property_exists( $response_body, 'message' ) ? $response_body->message : '';
402403
$data = property_exists( $response_body, 'data' ) ? $response_body->data : '';
403404

405+
if ( 500 == $response_code ) {
406+
return new WP_Error( 'wcc_server_error_response', 'The WooCommerce Services API encountered an error. Please try again.' );
407+
}
408+
404409
return new WP_Error(
405410
'wcc_server_error_response',
406411
sprintf(
407-
'Error: The WooCommerce Services server returned: %s %s ( %d )',
412+
'The WooCommerce Services API returned HTTP status code %d: %s. %s',
413+
$response_code,
408414
$error,
409-
$message,
410-
$response_code
415+
$message
411416
),
412417
$data
413418
);

0 commit comments

Comments
 (0)