Yoast\WP\SEO\AI\Authentication\Application

AI_Request_Sender::send │ public │ Yoast 1.0

Sends an authenticated AI request, falling back to the secondary strategy on persistent failure.

The fallback is only tried for failures that mean the primary strategy could not authenticate or reach the service; every authoritative answer the service gave (a content-filter rejection, a missing license, a consent or scope 403, a rate limit, a server error) propagates to the caller instead — see {@see self::is_fallback_eligible()}.

Kept public for backward compatibility — callers that have a pre-built Request may dispatch it directly. New call sites should prefer the named methods above.

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

Хуков нет.

Возвращает

Response. The parsed response.

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

$AI_Request_Sender = new AI_Request_Sender();
$AI_Request_Sender->send( $request, $user ): Response;
$request(Request) (обязательный)
The base request, without auth headers.
$user(WP_User) (обязательный)
The WP user the request is on behalf of.

Код AI_Request_Sender::send() Yoast 28.9

public function send( Request $request, WP_User $user ): Response {
	try {
		return $this->primary->send( $request, $user );
	}
	catch ( Remote_Request_Exception $exception ) {
		if ( ! $this->is_fallback_eligible( $exception ) ) {
			$this->logger->warning(
				'Primary AI auth strategy failed ({error_id}, HTTP {status}: {message}); the failure is not recoverable by the fallback, propagating to the caller.',
				$this->error_context( $exception ),
			);
			throw $exception;
		}
		if ( $this->fallback === null ) {
			$this->logger->warning(
				'Primary AI auth strategy failed ({error_id}, HTTP {status}: {message}); no fallback configured, giving up.',
				$this->error_context( $exception ),
			);
			throw $exception;
		}
		$this->logger->warning(
			'Primary AI auth strategy failed ({error_id}, HTTP {status}: {message}); falling back to the secondary strategy.',
			$this->error_context( $exception ),
		);

		try {
			$response = $this->fallback->send( $request, $user );
		}
		catch ( Remote_Request_Exception $fallback_exception ) {
			$this->logger->warning(
				'Secondary AI auth strategy also failed ({error_id}, HTTP {status}: {message}); giving up.',
				$this->error_context( $fallback_exception ),
			);
			throw $fallback_exception;
		}

		$this->logger->debug( 'Secondary AI auth strategy succeeded after primary failure.' );
		return $response;
	}
}