/** * @param ClientHttpErrorEvent $event */ public function onClientHttpErrorEvent(ClientHttpErrorEvent $event) { //If we already are in intercepted response, don't do it again if ($this->intercepted) { return; } $response = $event->getResponse(); if (401 !== $response->getStatusCode()) { return; } try { $this->intercepted = true; $this->authenticateEntryPoint->login(); $originalRequest = $event->getOriginalRequest(); $interceptedResponse = $this->client->request($originalRequest['method'], $originalRequest['uri'], $originalRequest['queryParams'], $originalRequest['requestParams'], $originalRequest['option'], $originalRequest['secured']); $event->setInterceptedResponse($interceptedResponse); $event->stopPropagation(); } catch (Exception $e) { //Ignore any exception that got here } finally { $this->intercepted = false; } }
/** * @param string$method * @param string$uri * @param array $queryParams * @param array $requestParams * @param array $options * @param bool $secured * * @return array|stdClass * @throws GuzzleException * @throws Exception */ protected function request($method, $uri, array $queryParams = [], array $requestParams = [], array $options = [], $secured = true) { return $this->client->request($method, $uri, $queryParams, $requestParams, $options, $secured); }