/** * Constructor. * * @param string $uri * @param \http\Client\Response $response */ public function __construct($uri, \http\Client\Response $response) { try { $parent = $response->getParentMessage(); $location = $parent->getHeader('Location'); $this->uri = $location; } catch (HttpRuntimeException $e) { $this->uri = $uri; } $this->httpVersion = $response->getHttpVersion(); $this->code = $response->getResponseCode(); $this->_response = $response; foreach ($response->getHeaders() as $k => $v) { $this->headers[strtolower($k)] = $v; } }
/** * {@inheritdoc} * @see Scalr\Service\OpenStack\Client.ClientResponseInterface::hasError() */ public function hasError() { if (!isset($this->errorData)) { $this->errorData = false; $code = $this->response->getResponseCode(); if ($code < 200 || $code > 299) { $this->errorData = new ErrorData(); if ($this->format == AppFormat::APP_JSON) { $d = @json_decode($this->getContent()); if ($d === null) { $this->errorData->code = $code; $this->errorData->message = strip_tags($this->getContent()); $this->errorData->details = ''; } else { list(, $v) = each($d); if (is_object($v)) { $this->errorData->code = isset($v->code) ? $v->code : 0; $this->errorData->message = $v->message; $this->errorData->details = isset($v->details) ? (string) $v->details : ''; } else { //QuantumError $this->errorData->code = $code; $this->errorData->message = (string) $v; $this->errorData->details = ''; } } } else { if ($this->format == AppFormat::APP_XML) { $d = simplexml_load_string($this->getContent()); $this->errorData->code = $code; $this->errorData->message = isset($d->message) ? (string) $d->message : ''; $this->errorData->details = isset($d->details) ? (string) $d->details : ''; } else { throw new \InvalidArgumentException(sprintf('Unexpected application format "%s" in class %s', (string) $this->format, get_class($this))); } } throw OpenStackResponseErrorFactory::make($this->errorData); } } return $this->errorData; }
/** * {@inheritdoc} * @see \Scalr\Service\Azure\Client\ClientResponseInterface::getResponseCode() */ public function getResponseCode() { return $this->httpResponse->getResponseCode(); }