Beispiel #1
0
 /**
  * If possible, set a cache response on a cURL exception
  *
  * @param Event $event
  *
  * @return null
  */
 public function onRequestException(Event $event)
 {
     if (!$event['exception'] instanceof CurlException) {
         return;
     }
     $request = $event['request'];
     if (!$this->canCache->canCacheRequest($request)) {
         return;
     }
     if ($response = $this->storage->fetch($request)) {
         $response->setHeader('Age', time() - strtotime($response->getDate() ?: 'now'));
         if (!$this->canResponseSatisfyFailedRequest($request, $response)) {
             return;
         }
         $request->getParams()->set('cache.hit', 'error');
         $request->setResponse($response);
         $this->addResponseHeaders($request, $response);
         $event->stopPropagation();
     }
 }
Beispiel #2
0
 /**
  * Default method that will throw exceptions if an unsuccessful response is received.
  *
  * @param Event $event Received
  * @throws BadResponseException if the response is not successful
  */
 public static function onRequestError(Event $event)
 {
     $e = BadResponseException::factory($event['request'], $event['response']);
     $event['request']->setState(self::STATE_ERROR, array('exception' => $e) + $event->toArray());
     throw $e;
 }
Beispiel #3
0
 /**
  * Throws a more meaningful request exception if available
  *
  * @param Event $event Event emitted
  */
 public function onRequestError(Event $event)
 {
     $e = $this->factory->fromResponse($event['request'], $event['response']);
     $event->stopPropagation();
     throw $e;
 }