Make WordPress Core

Opened 10 months ago

#60564 new defect (bug)

download_url() always returns error_code 'http_404' for any non-200 responses

Reported by: hinnerk's profile hinnerk Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.4.3
Component: HTTP API Keywords:
Focuses: Cc:

Description

Expected:
Return WP_Error code "http_406" if a 406 occurs while downloading the URL.
Return WP_Error code "http_500" if a 500 occurs while downloading the URL.
...

Actually doing it wrong:
download_url() always returns WP_Error code "http_404" on any non-200 status.

object(WP_Error)#11262 (3) {
  ["errors"]=>
  array(1) {
    ["http_404"]=>
    array(1) {
      [0]=>
      string(14) "Not Acceptable"
    }
  }
  ["error_data"]=>
  array(1) {
    ["http_404"]=>
    array(2) {
      ["code"]=>
      int(406)
      ["body"]=>
      string(0) ""
    }
  }
  ["additional_data":protected]=>
  array(0) {
  }
}

see https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/file.php#L1214

<?php
if ( 200 !== $response_code ) {
    // [...]
    return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ), $data );
}

Change History (0)

Note: See TracTickets for help on using tickets.