HttpTransporter::send( $request,  $options = null )

In this article

{@inheritDoc}

Source

public function send(Request $request, ?RequestOptions $options = null): Response
{
    $psr7Request = $this->convertToPsr7Request($request);
    // Merge request options with parameter options, with parameter options taking precedence
    $mergedOptions = $this->mergeOptions($request->getOptions(), $options);
    try {
        $hasOptions = $mergedOptions !== null;
        if ($hasOptions && $this->client instanceof ClientWithOptionsInterface) {
            $psr7Response = $this->client->sendRequestWithOptions($psr7Request, $mergedOptions);
        } elseif ($hasOptions && $this->isGuzzleClient($this->client)) {
            $psr7Response = $this->sendWithGuzzle($psr7Request, $mergedOptions);
        } else {
            $psr7Response = $this->client->sendRequest($psr7Request);
        }
    } catch (\WordPress\AiClientDependencies\Psr\Http\Client\NetworkExceptionInterface $e) {
        throw NetworkException::fromPsr18NetworkException($psr7Request, $e);
    } catch (\WordPress\AiClientDependencies\Psr\Http\Client\ClientExceptionInterface $e) {
        // Handle other PSR-18 client exceptions that are not network-related
        throw new RuntimeException(sprintf('HTTP client error occurred while sending request to %s: %s', $request->getUri(), $e->getMessage()), 0, $e);
    }
    return $this->convertFromPsr7Response($psr7Response);
}

Changelog

VersionDescription
0.2.0Added optional RequestOptions parameter and ClientWithOptions support.
0.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.