Yoast\WP\SEO\MyYoast_Client\User_Interface

Management_Route::error_response │ private │ Yoast 1.0

Builds an error response.

Defaults to HTTP 200 — the REST endpoint succeeded; the failure is in an upstream call or precondition, and the UI keys off error_code, not the HTTP status. Genuine 4xx (e.g. validation failures) pass an explicit status.

Метод класса: Management_Route{}

Хуков нет.

Возвращает

WP_REST_Response.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->error_response( $error_code, ?Throwable $exception, $status, $details ): WP_REST_Response;
$error_code(строка) (обязательный)
The machine-readable error code (looked up client-side in the i18n map).
?Throwable $exception
.
По умолчанию: null
$status(int)
The HTTP status.
По умолчанию: 200
$details(array<string, scalar>)
Optional extra fields the UI may use to enrich the error message.
По умолчанию: []

Код Management_Route::error_response() Yoast 28.7

private function error_response( string $error_code, ?Throwable $exception = null, int $status = 200, array $details = [] ): WP_REST_Response {
	if ( $exception !== null ) {
		$this->logger->warning(
			'MyYoast management error ({code}): {message}',
			[
				'code'    => $error_code,
				'message' => $exception->getMessage(),
			],
		);
	}

	$body = [
		'error_code' => $error_code,
		'status'     => $this->status_presenter->present(),
	];
	if ( $details !== [] ) {
		$body['details'] = $details;
	}

	return new WP_REST_Response( $body, $status );
}