/** * {@inheritdoc} */ protected function sendInternalRequest(InternalRequestInterface $internalRequest) { try { $this->eventDispatcher->dispatch(Events::PRE_SEND, $preSendEvent = new PreSendEvent($this, $internalRequest)); $response = parent::sendInternalRequest($preSendEvent->getRequest()); $this->eventDispatcher->dispatch(Events::POST_SEND, $postSendEvent = new PostSendEvent($this, $preSendEvent->getRequest(), $response)); if ($postSendEvent->hasException()) { throw $postSendEvent->getException(); } $response = $postSendEvent->getResponse(); } catch (HttpAdapterException $e) { $e->setRequest($internalRequest); $e->setResponse(isset($response) ? $response : null); $this->eventDispatcher->dispatch(Events::EXCEPTION, $exceptionEvent = new ExceptionEvent($this, $e)); if ($exceptionEvent->hasResponse()) { return $exceptionEvent->getResponse(); } throw $exceptionEvent->getException(); } return $response; }