Yoast\WP\SEO\AI\Authentication\Application
OAuth_Auth_Strategy::to_response
Converts a MyYoast HTTP_Response into the AI Response domain object.
HTTP_Response already carries a json-decoded body when the upstream returned JSON. For non-200 responses we extract message, error_code, and (for 402/429) missing_licenses from that decoded body. The body is re-encoded as a JSON string so the AI Response, which expects a string body, stays consistent with what the legacy Token path produces.
Метод класса: OAuth_Auth_Strategy{}
Хуков нет.
Возвращает
Response. The AI domain response.
Использование
// private - только в коде основоного (родительского) класса $result = $this->to_response( $http_response ): Response;
- $http_response(HTTP_Response) (обязательный)
- The MyYoast HTTP response.
Код OAuth_Auth_Strategy::to_response() OAuth Auth Strategy::to response Yoast 28.3
private function to_response( HTTP_Response $http_response ): Response {
$status = $http_response->get_status();
$headers = $http_response->get_headers();
$body = $http_response->get_body();
$message = '';
$error_code = '';
$missing_licenses = [];
if ( $status !== 200 && $status !== 0 && \is_array( $body ) ) {
$message = (string) ( $body['message'] ?? '' );
$error_code = (string) ( $body['error_code'] ?? '' );
if ( $status === 402 || $status === 429 ) {
$missing_licenses = (array) ( $body['missing_licenses'] ?? [] );
}
}
// phpcs:ignore Yoast.Yoast.JsonEncodeAlternative.Found -- Mirroring the body-encoding convention used elsewhere in the AI path.
$body_string = \is_array( $body ) ? WPSEO_Utils::format_json_encode( $body ) : (string) $body;
return new Response( $body_string, $status, $message, $error_code, $missing_licenses, $headers );
}