Google\Cloud\RequestWrapper::send PHP Метод

send() публичный Метод

Deliver the request.
public send ( Psr\Http\Message\RequestInterface $request, array $options = [] ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\RequestInterface Psr7 request.
$options array [optional] { Request options. @type int $retries Number of retries for a failed request. **Defaults to** `3`. @type array $httpOptions HTTP client specific configuration options. }
Результат Psr\Http\Message\ResponseInterface
    public function send(RequestInterface $request, array $options = [])
    {
        $retries = isset($options['retries']) ? $options['retries'] : $this->retries;
        $httpOptions = isset($options['httpOptions']) ? $options['httpOptions'] : $this->httpOptions;
        $backoff = new ExponentialBackoff($retries, $this->getRetryFunction());
        $signedRequest = $this->shouldSignRequest ? $this->signRequest($request) : $request;
        try {
            return $backoff->execute($this->httpHandler, [$signedRequest, $httpOptions]);
        } catch (\Exception $ex) {
            throw $this->convertToGoogleException($ex);
        }
    }

Usage Example

 public function testThrowsExceptionWithNonRetryableError()
 {
     $nonRetryableErrorMessage = '{"error": {"errors": [{"reason": "notAGoodEnoughReason"}]}}';
     $actualAttempts = 0;
     $hasTriggeredException = false;
     $requestWrapper = new RequestWrapper(['httpHandler' => function () use(&$actualAttempts, $nonRetryableErrorMessage) {
         $actualAttempts++;
         throw new \Exception($nonRetryableErrorMessage, 429);
     }]);
     try {
         $requestWrapper->send(new Request('GET', 'http://www.example.com'));
     } catch (\Exception $ex) {
         $hasTriggeredException = true;
     }
     $this->assertTrue($hasTriggeredException);
     $this->assertEquals(1, $actualAttempts);
 }