On this page
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
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| rest_convert_error_to_response() wp-includes/rest-api.php | Converts an error to a response object. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Server::serve_batch_request_v1() wp-includes/rest-api/class-wp-rest-server.php | Serves the batch/v1 request. |
| WP_REST_Server::respond_to_request() wp-includes/rest-api/class-wp-rest-server.php | Dispatches the request to the callback handler. |
| WP_REST_Server::dispatch() wp-includes/rest-api/class-wp-rest-server.php | Matches the request to a callback and call it. |
| WP_REST_Server::serve_request() wp-includes/rest-api/class-wp-rest-server.php | Handles serving a REST API request. |
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