/**
  * {@inheritdoc}
  */
 protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
 {
     try {
         $this->eventDispatcher->dispatch(Events::REQUEST_CREATED, $requestCreatedEvent = new RequestCreatedEvent($this, $internalRequest));
         $response = parent::doSendInternalRequest($requestCreatedEvent->getRequest());
         $this->eventDispatcher->dispatch(Events::REQUEST_SENT, $requestSentEvent = new RequestSentEvent($this, $requestCreatedEvent->getRequest(), $response));
         if ($requestSentEvent->hasException()) {
             throw $requestSentEvent->getException();
         }
         $response = $requestSentEvent->getResponse();
     } catch (HttpAdapterException $e) {
         $e->setRequest($internalRequest);
         $e->setResponse(isset($response) ? $response : null);
         $this->eventDispatcher->dispatch(Events::REQUEST_ERRORED, $exceptionEvent = new RequestErroredEvent($this, $e));
         if ($exceptionEvent->hasResponse()) {
             return $exceptionEvent->getResponse();
         }
         throw $exceptionEvent->getException();
     }
     return $response;
 }
 /**
  * On post send event.
  *
  * We reach this event when the request has not been intercepted.
  *
  * @param RequestSentEvent $event The post send event.
  */
 public function onPostSend(RequestSentEvent $event)
 {
     if (!$this->isRecording) {
         return;
     }
     $request = $event->getRequest();
     if (!$this->currentTape->hasTrackForRequest($request)) {
         return;
     }
     $track = $this->currentTape->getTrackForRequest($request);
     $this->currentTape->finishRecording($track, $event->getResponse(), $event->hasException() ? $event->getException() : null);
 }