WordPress at a glance
function is not described

WP_REST_Server::json_error() protected WP 4.4.0

Retrieves an appropriate error representation in JSON.

Note: This should only be used in WP_REST_Server::serve_request(), as it cannot handle WP_Error internally. All callbacks and other internal methods should instead return a WP_Error with the data set to an array that includes a 'status' key, with the value being the HTTP status to send.

{} It's a method of the class: WP_REST_Server{}

No Hooks.

Return

String. JSON representation of the error

Usage

// protected - for code of main (parent) or child class
$result = $this->json_error( $code, $message, $status );
$code(string) (required)
WP_Error-style code.
$message(string) (required)
Human-readable message.
$status(int)
HTTP status code to send.
Default: null

Changelog

Since 4.4.0 Introduced.

Code of WP_REST_Server::json_error() WP 5.5.1

<?php
protected function json_error( $code, $message, $status = null ) {
	if ( $status ) {
		$this->set_status( $status );
	}

	$error = compact( 'code', 'message' );

	return wp_json_encode( $error );
}