WordPress.org

Make WordPress Core

Opened 3 weeks ago

Last modified 13 days ago

#53056 new defect (bug)

REST API json_encode error returns 500 data->status in body(Correct) but 200 in actual status(Incorrect).

Reported by: lalitjalandhar Owned by:
Milestone: 5.8 Priority: normal
Severity: normal Version:
Component: General Keywords: needs-patch good-first-bug needs-unit-tests
Focuses: rest-api Cc:

Description

<?php
add_action( 'rest_api_init', function() {
        register_rest_route(
                'v3',
                '/my-custom-route',
                array(
                        array(
                                'methods'             => \WP_REST_Server::READABLE,
                                'callback'            => function() {
                                        return new \WP_REST_Response(INF);
                                },
                                'permission_callback' => '__return_true',
                                'args'                => array(),
                        ),
                )
        );
});

Attachments (1)

nan.PNG (19.1 KB) - added by lalitjalandhar 3 weeks ago.
postman screen shot

Download all attachments as: .zip

Change History (2)

@lalitjalandhar
3 weeks ago

postman screen shot

#1 @desrosj
13 days ago

  • Focuses rest-api added
  • Keywords needs-patch good-first-bug needs-unit-tests added
  • Milestone changed from Awaiting Review to 5.8

Thanks for this one, @lalitjalandhar. And welcome to Trac!

It seems that there is a missing set_status() call here. Would you be interested in creating a patch?

It would also be nice to add a few tests to confirm the desired behavior after these changes.

Note: See TracTickets for help on using tickets.