예제 #1
0
 /**
  * @param CurlException $e
  * @return StorageApiEvent
  */
 public function curlError(CurlException $e)
 {
     $event = $this->prepareEvent();
     $event->setMessage(sprintf(self::MESSAGE_END, $this->task->getRunUrl()))->setDescription($e->getError())->setType(StorageApiEvent::TYPE_WARN)->setResults(array('response' => $e->getError(), 'code' => $e->getErrorNo()));
     $this->save($event);
     return $event;
 }
 public function testStoresCurlError()
 {
     $e = new CurlException();
     $this->assertNull($e->getError());
     $this->assertNull($e->getErrorNo());
     $this->assertSame($e, $e->setError('test', 12));
     $this->assertEquals('test', $e->getError());
     $this->assertEquals(12, $e->getErrorNo());
 }
 public function testRetriesWithExponentialDelay()
 {
     $this->assertNotEmpty(CurlBackoffStrategy::getDefaultFailureCodes());
     $strategy = new CurlBackoffStrategy();
     $this->assertTrue($strategy->makesDecision());
     $request = $this->getMock('Guzzle\\Http\\Message\\Request', array(), array(), '', false);
     $e = new CurlException();
     $e->setError('foo', CURLE_BAD_CALLING_ORDER);
     $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, null, $e));
     foreach (CurlBackoffStrategy::getDefaultFailureCodes() as $code) {
         $this->assertEquals(0, $strategy->getBackoffPeriod(0, $request, null, $e->setError('foo', $code)));
     }
 }
 public function testStoresCurlError()
 {
     $e = new CurlException();
     $this->assertNull($e->getError());
     $this->assertNull($e->getErrorNo());
     $this->assertSame($e, $e->setError('test', 12));
     $this->assertEquals('test', $e->getError());
     $this->assertEquals(12, $e->getErrorNo());
     $handle = new CurlHandle(curl_init(), array());
     $e->setCurlHandle($handle);
     $this->assertSame($handle, $e->getCurlHandle());
     $handle->close();
 }
 public function testUpdatesRequestForRetry()
 {
     $request = new Request('GET', 'http://www.example.com');
     $request->setState('transfer');
     $response = new Response(500);
     $handle = $this->getMockBuilder('Guzzle\\Http\\Curl\\CurlHandle')->disableOriginalConstructor()->getMock();
     $e = new CurlException();
     $e->setCurlHandle($handle);
     $plugin = new BackoffPlugin(new ConstantBackoffStrategy(10));
     $plugin->addSubscriber($this);
     $event = new Event(array('request' => $request, 'response' => $response, 'exception' => $e));
     $plugin->onRequestSent($event);
     $this->assertEquals(array('request' => $request, 'response' => $response, 'handle' => $handle, 'retries' => 1, 'delay' => 10), $this->readAttribute($this->retried, 'context'));
     $plugin->onRequestSent($event);
     $this->assertEquals(array('request' => $request, 'response' => $response, 'handle' => $handle, 'retries' => 2, 'delay' => 10), $this->readAttribute($this->retried, 'context'));
 }
예제 #6
0
 /**
  * curl error
  * @param  \Guzzle\Common\Event $event
  * @throws KintoneException
  */
 public function onRequestException(Event $event)
 {
     $this->request = $event->offsetGet('request');
     $this->response = $event->offsetGet('response');
     $this->exception = $event->offsetGet('exception');
     if ($this->exception instanceof \Guzzle\Http\Exception\CurlException) {
         $errorNumber = $this->exception->getErrorNo();
         switch ($errorNumber) {
             case 6:
                 throw new KintoneException('kintone.unknown_url');
             case 35:
                 throw new KintoneException('kintone.invalid_cert');
             default:
                 throw new KintoneException('kintone.invalid_auth');
         }
     }
     throw new \Exception($this->exception->getMessage());
 }
예제 #7
0
 /**
  * Check if a cURL transfer resulted in what should be an exception
  *
  * @param RequestInterface $request Request to check
  * @param CurlHandle       $handle  Curl handle object
  * @param array            $curl    Array returned from curl_multi_info_read
  *
  * @return CurlException|bool
  */
 private function isCurlException(RequestInterface $request, CurlHandle $handle, array $curl)
 {
     if (CURLM_OK == $curl['result'] || CURLM_CALL_MULTI_PERFORM == $curl['result']) {
         return false;
     }
     $handle->setErrorNo($curl['result']);
     $e = new CurlException(sprintf('[curl] %s: %s [url] %s', $handle->getErrorNo(), $handle->getError(), $handle->getUrl()));
     $e->setCurlHandle($handle)->setRequest($request)->setCurlInfo($handle->getInfo())->setError($handle->getError(), $handle->getErrorNo());
     return $e;
 }
예제 #8
0
파일: VarnishTest.php 프로젝트: ataxel/tp
    public function curlExceptionProvider()
    {
        $requestException = new RequestException('request');
        $requestException->setRequest(new Request('GET', '/'));

        $curlException = new CurlException('curl');
        $curlException->setRequest(new Request('GET', '/'));
        return array(
            array($curlException, '\FOS\HttpCache\Exception\ProxyUnreachableException'),
            array($requestException, '\FOS\HttpCache\Exception\ProxyResponseException'),
            array(new \InvalidArgumentException('something'), '\InvalidArgumentException'),
        );
    }
 /**
  * Check if a cURL transfer resulted in what should be an exception
  *
  * @param RequestInterface $request Request to check
  * @param CurlHandle $handle Curl handle object
  * @param array $curl Curl message returned from curl_multi_info_read
  *
  * @return Exception|bool
  */
 private function isCurlException(RequestInterface $request, CurlHandle $handle, array $curl)
 {
     if (CURLE_OK == $curl['result']) {
         return false;
     }
     $handle->setErrorNo($curl['result']);
     $e = new CurlException(sprintf('[curl] %s: %s [url] %s [info] %s [debug] %s', $handle->getErrorNo(), $handle->getError(), $handle->getUrl(), var_export($handle->getInfo(), true), $handle->getStderr()));
     $e->setRequest($request)->setError($handle->getError(), $handle->getErrorNo());
     return $e;
 }
예제 #10
0
 /**
  * @param CurlException $exception\
  */
 private function processCurlError(CurlException $exception)
 {
     $error = 'Curl error: ' . $exception->getMessage();
     $this->log->error($error);
     $this->throwCurlException($exception->getErrorNo(), $exception->getError());
 }
예제 #11
0
 /**
  * @covers Guzzle\Http\Plugin\ExponentialBackoffPlugin::onRequestSent
  */
 public function testExponentiallyBacksOffCurlErrors()
 {
     $plugin = $this->getMock('Guzzle\\Http\\Plugin\\ExponentialBackoffPlugin', array('retryRequest'));
     // Mock the retryRequest method so that it does nothing, but ensure
     // that it is called exactly once
     $plugin->expects($this->once())->method('retryRequest')->will($this->returnValue(null));
     // Create an exception that is found in the default curl exception list
     $exception = new CurlException('Curl');
     $exception->setError('foo', CURLE_OPERATION_TIMEOUTED);
     // Create a dummy event to send to the plugin
     $event = new Event(array('request' => new Request('GET', 'http://test.com'), 'response' => null, 'exception' => $exception));
     // Ensure the it uses the name we're looking for
     $event->setName('request.exception');
     // Trigger the event
     $plugin->onRequestSent($event);
 }