wordpress / latest / classes / wp_rest_server / error_to_response.html

WP_REST_Server::error_to_response( WP_Error $error ): WP_REST_Response

Converts an error to a response object.

Description

This iterates over all error codes and messages to change it into a flat array. This enables simpler client behaviour, as it is represented as a list in JSON rather than an object/map.

Parameters

$error WP_Error Required
WP_Error instance.

Return

WP_REST_Response List of associative arrays with code and message keys.

Source

File: wp-includes/rest-api/class-wp-rest-server.php. View all references

protected function error_to_response( $error ) {
	return rest_convert_error_to_response( $error );
}

Used By

Used By Description

Changelog

Version Description
5.7.0 Converted to a wrapper of rest_convert_error_to_response() .
4.4.0 Introduced.

© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_server/error_to_response