예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function onRequestErrored(RequestErroredEvent $event)
 {
     if (($request = $this->retry->retry($event->getException()->getRequest())) === false) {
         return;
     }
     $event->getException()->setRequest($request);
     try {
         $event->setResponse($event->getHttpAdapter()->sendRequest($request));
     } catch (HttpAdapterException $e) {
         $event->setException($e);
     }
 }
 /**
  * We arrive here when the request has successfully been intercepted.
  *
  * @param RequestErroredEvent $event The exception event.
  */
 public function onException(RequestErroredEvent $event)
 {
     if (!$this->isRecording) {
         return;
     }
     $exception = $event->getException();
     $request = $exception->getRequest();
     if (!$this->currentTape->hasTrackForRequest($request)) {
         return;
     }
     $track = $this->currentTape->getTrackForRequest($request);
     if (!$exception instanceof TapeRecorderException) {
         // Normal exception, let's store it in the track for the next time
         $this->currentTape->finishRecording($track, $event->getResponse(), $event->getException());
         return;
     }
     // We are in replay mode
     if ($track->hasResponse()) {
         $event->setResponse($track->getResponse());
     }
     if ($track->hasException()) {
         $event->setException($track->getException());
     }
 }