コード例 #1
0
 /**
  * @param ResponseInterface[] $responses
  *
  * @return ProxyResponseException[]
  */
 private function handleErrorResponses(array $responses)
 {
     $exceptions = [];
     foreach ($responses as $response) {
         if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) {
             $exceptions[] = ProxyResponseException::proxyResponse($response);
         }
     }
     return $exceptions;
 }
コード例 #2
0
ファイル: CacheInvalidatorTest.php プロジェクト: ataxel/tp
    /**
     * @expectedException \FOS\HttpCache\Exception\ExceptionCollection
     */
    public function testProxyClientExceptionsAreLogged()
    {
        $unreachableException = ProxyUnreachableException::proxyUnreachable('http://127.0.0.1', 'Couldn\'t connect to host');
        $responseException    = ProxyResponseException::proxyResponse('http://127.0.0.1', 403, 'Forbidden');

        $exceptions = new ExceptionCollection();
        $exceptions->add($unreachableException)->add($responseException);

        $proxyClient = \Mockery::mock('\FOS\HttpCache\ProxyClient\ProxyClientInterface')
            ->shouldReceive('flush')->once()->andThrow($exceptions)
            ->getMock();

        $cacheInvalidator = new CacheInvalidator($proxyClient);

        $logger = \Mockery::mock('\Psr\Log\LoggerInterface')
            ->shouldReceive('log')->once()
            ->with(
                'critical',
                'Request to caching proxy at http://127.0.0.1 failed with message "Couldn\'t connect to host"',
                array(
                    'exception' => $unreachableException
                )
            )
            ->shouldReceive('log')->once()
            ->with('critical', '403 error response "Forbidden" from caching proxy at http://127.0.0.1', array('exception' => $responseException))
            ->getMock();

        $cacheInvalidator->addSubscriber(new LogSubscriber($logger));

        $cacheInvalidator
            ->flush()
        ;
    }
コード例 #3
0
ファイル: AbstractProxyClient.php プロジェクト: ataxel/tp
    /**
     * Handle request exception
     *
     * @param GuzzleExceptionCollection $exceptions
     *
     * @throws ExceptionCollection
     */
    protected function handleException(GuzzleExceptionCollection $exceptions)
    {
        $collection = new ExceptionCollection();

        foreach ($exceptions as $exception) {
            if ($exception instanceof CurlException) {
                // Caching proxy unreachable
                $e = ProxyUnreachableException::proxyUnreachable(
                    $exception->getRequest()->getHost(),
                    $exception->getMessage(),
                    $exception->getRequest()->getRawHeaders(),
                    $exception
                );
            } elseif ($exception instanceof RequestException) {
                // Other error
                $e = ProxyResponseException::proxyResponse(
                    $exception->getRequest()->getHost(),
                    $exception->getCode(),
                    $exception->getMessage(),
                    $exception->getRequest()->getRawHeaders(),
                    $exception
                );
            } else {
                // Unexpected exception type
                $e = $exception;
            }

            $collection->add($e);
        }

        throw $collection;
    }
コード例 #4
0
 /**
  * Send all pending invalidation requests and make sure the requests have terminated and gather exceptions.
  *
  * @return int The number of cache invalidations performed per caching server
  *
  * @throws ExceptionCollection If any errors occurred during flush
  */
 public function flush()
 {
     $queue = $this->queue;
     $this->queue = [];
     /** @var Promise[] $promises */
     $promises = [];
     $exceptions = new ExceptionCollection();
     foreach ($queue as $request) {
         foreach ($this->fanOut($request) as $proxyRequest) {
             $promises[] = $this->httpClient->sendAsyncRequest($proxyRequest);
         }
     }
     if (count($exceptions)) {
         throw new ExceptionCollection($exceptions);
     }
     foreach ($promises as $promise) {
         try {
             $promise->wait();
         } catch (HttpException $exception) {
             $exceptions->add(ProxyResponseException::proxyResponse($exception->getResponse()));
         } catch (RequestException $exception) {
             $exceptions->add(ProxyUnreachableException::proxyUnreachable($exception));
         } catch (\Exception $exception) {
             $exceptions->add(new InvalidArgumentException($exception));
         }
     }
     if (count($exceptions)) {
         throw $exceptions;
     }
     return count($queue);
 }