Example #1
0
 /**
  * @param \Exception $exception
  * @return GuzzleRestException
  */
 public static function createFromException(\Exception $exception)
 {
     if ($exception instanceof BadResponseException && $exception->getResponse()) {
         $url = $exception->getRequest() ? (string) $exception->getRequest()->getUrl() : null;
         $result = GuzzleRestException::createFromResponse(new GuzzleRestResponse($exception->getResponse(), $url), null, $exception);
     } else {
         /** @var GuzzleRestException $result */
         $result = new static($exception->getMessage(), $exception->getCode(), $exception);
     }
     return $result;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function xml()
 {
     try {
         $result = $this->response->xml();
     } catch (\Exception $exception) {
         throw GuzzleRestException::createFromException($exception);
     }
     return $result;
 }
Example #3
0
 /**
  * Performed request and return response
  *
  * @param string $method
  * @param string $url
  * @param array $params
  * @param mixed $data
  * @param array $headers
  * @param array $options
  * @return string
  * @throws GuzzleRestException
  */
 public function performRequest($method, $url, array $params = [], $data = null, array $headers = [], array $options = [])
 {
     $url = $this->buildUrl($url, $params);
     $options = array_merge($this->defaultOptions, $options);
     if (is_array($data) && (!isset($headers['Content-Type']) || $headers['Content-Type'] == 'application/json')) {
         $headers['Content-Type'] = 'application/json';
         $data = json_encode($data);
     }
     try {
         $this->lastGuzzleRequest = $request = $this->getGuzzleClient()->createRequest($method, $url, $headers, $data, $options);
         $response = $request->send();
     } catch (\Exception $exception) {
         throw GuzzleRestException::createFromException($exception);
     }
     $this->lastResponse = new GuzzleRestResponse($response, (string) $request->getUrl());
     return $this->lastResponse;
 }