RestApiResponse: response code handling

This commit is contained in:
Thomas Gelf 2016-03-17 01:07:04 +01:00
parent 228f72db91
commit 95cb1498bc
1 changed files with 13 additions and 1 deletions

View File

@ -34,7 +34,19 @@ class RestApiResponse
public function getSingleResult() public function getSingleResult()
{ {
return $this->results[0]->result; if ($this->isErrorCode($this->results[0]->code)) {
throw new IcingaException(
$this->results[0]->status
);
} else {
return $this->results[0]->result;
}
}
protected function isErrorCode($code)
{
$code = (int) ceil($code);
return $code >= 400;
} }
protected function extractResult($results, $desiredKey, $filter = array()) protected function extractResult($results, $desiredKey, $filter = array())