We’ve got some custom endpoints set up that do various things, which we access via /wp/wp-admin/admin-ajax.php?action=some_action

However whenever there is an error as we’re developing, such as syntax, logical, fatal etc, we simply get “500 Internal Server Error”

Every other page on the site when there’s an error, it gives us the PHP error.

We have to then open our PHP Log file to see the error.

Is there something in wordpress that disables displaying of errors on these URLs? and if so, how can we prevent this to allow rendering of the errors on the browser?

3 s
3

WordPress by default hide errors for ajax request call. This can be confirmed from the source file wp-includes/load.php#L352, here:

if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
    @ini_set( 'display_errors', 0 );
}

See the function wp_doing_ajax() is being used in the conditional statement thus the display_errors is being set.

To workaround this, you need to turn on error reporting manually at top of your ajax function call as suggested by @Friss.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *