WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 3 weeks ago

#47188 assigned defect (bug)

Ensure that valid json is return for rest api, even when correct headers not sent.

Reported by: spacedmonkey Owned by: spacedmonkey
Milestone: 5.5 Priority: normal
Severity: normal Version: 4.4
Component: REST API Keywords: servehappy needs-patch
Focuses: rest-api Cc:

Description

Current when wp_die is called in php fatal error handler, valid json is only returned when json headers are returned as the function wp_is_json_request is used. See #45933.

However, core could do more to return json when it knows the current request is a REST API call.

Attachments (2)

47188.diff (1.2 KB) - added by spacedmonkey 14 months ago.
47188.2.diff (1.3 KB) - added by spacedmonkey 3 months ago.

Download all attachments as: .zip

Change History (21)

#1 @spacedmonkey
14 months ago

  • Keywords needs-patch added; has-patch removed

Related: #34999

@spacedmonkey
14 months ago

#2 @spacedmonkey
14 months ago

  • Keywords has-patch added; needs-patch removed

First patch 47188.diff to kick discussion.

This ticket was mentioned in Slack in #core-php by spacedmonkey. View the logs.


13 months ago

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


13 months ago

#5 @spacedmonkey
12 months ago

  • Component changed from REST API to Site Health

#6 @spacedmonkey
8 months ago

  • Component changed from Site Health to REST API

Changing to REST API focus, as this makes more sense.

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.


8 months ago

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.


3 months ago

#9 @spacedmonkey
3 months ago

Updated patch based on @TimothyBlynJacobs 's feedback.

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.


3 months ago

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.


3 months ago

This ticket was mentioned in PR #215 on WordPress/wordpress-develop by spacedmonkey.


3 months ago

<!--
Hi there! Thanks for contributing to WordPress!

Pull Requests in this GitHub repository must be linked to a ticket in the WordPress Core Trac instance (https://core.trac.wordpress.org), and are only used for code review. No pull requests will be merged on GitHub.

See the WordPress Handbook page on using PRs for Code Review more information: https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/

If this is your first time contributing, you may also find reviewing these guides first to be helpful:

-->

Trac ticket: https://core.trac.wordpress.org/ticket/47188

#13 @prbot
3 months ago

spacedmonkey commented on PR #215:

@TimothyBJacobs For your review

#14 @spacedmonkey
3 months ago

  • Milestone changed from Awaiting Review to Future Release
  • Owner set to TimothyBlynJacobs
  • Status changed from new to assigned

Assigning ticket to @TimothyBlynJacobs for review.

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.


3 months ago

#16 @TimothyBlynJacobs
2 months ago

  • Milestone changed from Future Release to 5.5

#17 @TimothyBlynJacobs
2 months ago

  • Keywords needs-patch added; has-patch removed
  • Owner changed from TimothyBlynJacobs to spacedmonkey

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
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.

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.


4 weeks ago

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


3 weeks ago

Note: See TracTickets for help on using tickets.