WP_REST_Server::error_to_response()
Converts an error to a response object.
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.
Method of the class: WP_REST_Server{}
No Hooks.
Return
WP_REST_Response
. List of associative arrays with code and message keys.
Usage
// protected - for code of main (parent) or child class $result = $this->error_to_response( $error );
- $error(WP_Error) (required)
- WP_Error instance.
Changelog
Since 4.4.0 | Introduced. |
Since 5.7.0 | Converted to a wrapper of rest_convert_error_to_response(). |
WP_REST_Server::error_to_response() WP REST Server::error to response code WP 6.1.1
protected function error_to_response( $error ) { return rest_convert_error_to_response( $error ); }