WP_REST_Server::error_to_response() WordPress Method

The WP_REST_Server::error_to_response() method is used to generate a WP_Error object from a given HTTP status code and message. This is useful for creating error responses to REST requests.

WP_REST_Server::error_to_response( WP_Error $error ) #

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.


Top ↑

Parameters

$error

(WP_Error)(Required)WP_Error instance.


Top ↑

Return

(WP_REST_Response) List of associative arrays with code and message keys.


Top ↑

Source

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

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


Top ↑

Changelog

Changelog
VersionDescription
5.7.0Converted to a wrapper of rest_convert_error_to_response().
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.