[wp-trac] [WordPress Trac] #47188: Ensure that valid json is return for rest api, even when correct headers not sent.

WordPress Trac noreply at wordpress.org
Sat Apr 25 22:47:21 UTC 2020


#47188: Ensure that valid json is return for rest api, even when correct headers
not sent.
------------------------------------+---------------------------
 Reporter:  spacedmonkey            |       Owner:  spacedmonkey
     Type:  defect (bug)            |      Status:  assigned
 Priority:  normal                  |   Milestone:  5.5
Component:  REST API                |     Version:  4.4
 Severity:  normal                  |  Resolution:
 Keywords:  servehappy needs-patch  |     Focuses:  rest-api
------------------------------------+---------------------------
Changes (by TimothyBlynJacobs):

 * keywords:  servehappy has-patch => servehappy needs-patch
 * owner:  TimothyBlynJacobs => spacedmonkey


Comment:

 This doesn't appear to work in my testing. Given the following filter and
 making a request to `http://localhost:8889/wp-json/wp/v2/posts` I get the
 HTML WSOD page.

 {{{#!php
 <?php
 add_filter( 'rest_prepare_post', function ( WP_REST_Response $response ) {
         throw new \Exception( 'test' );
 } );
 }}}

 `rest_pre_serve_request` is fired immediately before rendering the output
 of the response, which is too late for any errors that happen during the
 meaningful parts of the request.

 It may be better to add a `defined( 'REST_REQUEST' ) && REST_REQUEST`
 check in `wp_die` when choosing the `wp_die` handler.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47188#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list