/** * {@inheritdoc} */ public function onException(ExceptionEvent $event) { if (!$this->retry->retry($event->getException()->getRequest())) { return; } try { $event->setResponse($event->getHttpAdapter()->sendRequest($event->getException()->getRequest())); } catch (HttpAdapterException $e) { $event->setException($e); } }
/** * {@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; }
/** * On exception event. * * @param \Ivory\HttpAdapter\Event\ExceptionEvent $event The event. */ public function onException(ExceptionEvent $event) { $this->stopwatch->stop($this->getStopwatchName($event->getHttpAdapter(), $event->getException()->getRequest())); }
/** * On exception event. * * @param \Ivory\HttpAdapter\Event\ExceptionEvent $event The exception event. */ public function onException(ExceptionEvent $event) { if ($event->getException()->hasResponse()) { $this->cookieJar->extract($event->getException()->getRequest(), $event->getException()->getResponse()); } }
/** * Sends an internal request. * * @param \Ivory\HttpAdapter\Message\InternalRequestInterface $internalRequest The internal request. * * @throws \Ivory\HttpAdapter\HttpAdapterException If an error occurred. * * @return \Ivory\HttpAdapter\Message\ResponseInterface The response. */ private function sendInternalRequest(InternalRequestInterface $internalRequest) { try { if ($this->configuration->hasEventDispatcher()) { $this->configuration->getEventDispatcher()->dispatch(Events::PRE_SEND, $preSendEvent = new PreSendEvent($this, $internalRequest)); $internalRequest = $preSendEvent->getRequest(); } $response = $this->doSendInternalRequest($internalRequest); if ($this->configuration->hasEventDispatcher()) { $this->configuration->getEventDispatcher()->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); if ($this->configuration->hasEventDispatcher()) { $this->configuration->getEventDispatcher()->dispatch(Events::EXCEPTION, $exceptionEvent = new ExceptionEvent($this, $e)); if ($exceptionEvent->hasResponse()) { return $exceptionEvent->getResponse(); } $e = $exceptionEvent->getException(); } throw $e; } return $response; }
/** * On exception event. * * @param \Ivory\HttpAdapter\Event\ExceptionEvent $event The exception event. */ public function onException(ExceptionEvent $event) { $this->collectException($event->getHttpAdapter(), $event->getException()); }
/** * On exception event. * * @param \Ivory\HttpAdapter\Event\ExceptionEvent $event The exception event. */ public function onException(ExceptionEvent $event) { $event->getException()->setRequest($this->error($event->getHttpAdapter(), $event->getException())); }