Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#49426 closed defect (bug) (fixed)

Site Health: the Rest API test doesn't display the WP_Error code

Reported by: afercia's profile afercia Owned by: desrosj's profile desrosj
Milestone: 5.4 Priority: normal
Severity: normal Version: 5.2
Component: Site Health Keywords: has-screenshots has-patch commit
Focuses: ui Cc:


When the Site Health "Rest API availability" test runs and returns a WP_Error, it is supposed to display:

  • the WP_Error code
  • the WP_Error message

However, it fails to display the error code and shows just the error message. See in the screenshot below and notice there's nothing within the square brackets in the error details.

Turns out wp_remote_retrieve_response_code() is used in the related code. However, when there's a WP_Error this function returns an empty string. In fact, it is designed to get HTTP errors code, while for the errors wrapped by WP_Error the related function get_error_message() should be used instead.

Attachments (6)

curl error no error code.png (92.4 KB) - added by afercia 4 years ago.
49426.diff (1.2 KB) - added by afercia 4 years ago.
curl error with error code.png (95.6 KB) - added by afercia 4 years ago.
49426.2.diff (1.8 KB) - added by desrosj 4 years ago.
loopback-test.png (71.8 KB) - added by desrosj 4 years ago.
loopback-fixed.png (67.1 KB) - added by desrosj 4 years ago.

Download all attachments as: .zip

Change History (13)

#1 @afercia
4 years ago

Quickest way to reproduce:

  • go to the Site Health page
  • add sleep( 10 ); to your wp-config.php file
  • remember to pick the right wp-config file depending whether you're running WordPress from the src or thebuild directory, in the former case you'll also need to build
  • this will make the test cURL request timeout
  • refresh the Site Health page
  • wait for 10 seconds :)
  • see the REST API test listed in the critical issues and expand it
  • see there's nothing displayed within the square brackets

4 years ago

#2 @afercia
4 years ago

  • Keywords has-patch added


  • Uses get_error_message() for the WP_Error case
  • WP_Error error codes aren't that useful for users, for example: bad_request, http_request_failed, etc.: moved the error code at the end of the string in a less prominent place
  • not sure why the WP_Error error code was displayed between square brackets while the HTTP error codes are displayed between parenthesis: standardized to parenthesis
  • tried to clarify the related translators comments

See the screenshot below with the error code now displayed at the end of the string.

This ticket was mentioned in Slack in #core-site-health by afercia. View the logs.

4 years ago

#4 @SergeyBiryukov
4 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 5.4

This ticket was mentioned in Slack in #core-site-health by afragen. View the logs.

4 years ago

4 years ago

4 years ago

#6 @desrosj
4 years ago

This looks good. But in my testing, I also noticed the same issue for the loopback test. 49426.2.diff fixes the issue there as well.

#7 @desrosj
4 years ago

  • Owner set to desrosj
  • Resolution set to fixed
  • Status changed from new to closed

In 47306:

Site Health: Display the REST API test error codes correctly.

This change fixes an issue where the error codes associated with failed REST API tests are not being printed to the screen. In addition, the square brackets have been replaced with parentheses for consistency, and the error code (which is much less useful to end-users than the error message itself) has been moved to the end of the line.

This also clarifies the associated translator comments.

Props afercia, desrosj.
Fixes #49426.

Note: See TracTickets for help on using tickets.