[wp-trac] [WordPress Trac] #60014: REST endpoint: Output "server errors" if WP_DEBUG = true (register_rest_route)

WordPress Trac noreply at wordpress.org
Tue Dec 5 15:32:19 UTC 2023


#60014: REST endpoint: Output "server errors" if WP_DEBUG = true
(register_rest_route)
-------------------------+-----------------------------
 Reporter:  ecc          |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  REST API     |    Version:  6.4
 Severity:  normal       |   Keywords:
  Focuses:  rest-api     |
-------------------------+-----------------------------
 While developing a custom REST endpoint (with WP_DEBUG = true), an
 "internal server error" JSON response is not really helpful for the
 developer.

 It does not show the actual error message, which makes it useless.

 (Info: In my case, the error is a wrong method return type)


 {{{
 {
     "code": "internal_server_error",
     "message": "<p>There has been a critical error on this website.<\/p>",
     "data": {
         "status": 500
     },
     "additional_errors": []
 }
 }}}


 **Idea:**

 If WP_DEBUG = true, output the full error message in the data array. (see
 below)


 {{{
 {
     "code": "internal_server_error",
     "message": "<p>There has been a critical error on this website.<\/p>",
     "data": {
         "status": 500,
         "error": "Uncaught TypeError:
 PluginConfig::getWpOptionStorageName(): Return value must be of type
 array, string returned in ..."
     },
     "additional_errors": []
 }
 }}}


 **Observation**

 In _wp_die_process_input(), functions.php line 4255, the errors are
 resetted.

 If the errors aren't resetted here, the 'additional_errors' will contain
 the error too.

 Maybe it's possible to output them only if WP_DEBUG = true.


 {{{
 // unset( $errors[0] );
 $args['additional_errors'] = array_values( $errors );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60014>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list