RestApiClient: handle non-json errors
This commit is contained in:
parent
a0c418a952
commit
9ea08647dc
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Core;
|
namespace Icinga\Module\Director\Core;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class RestApiClient
|
class RestApiClient
|
||||||
{
|
{
|
||||||
protected $version = 'v1';
|
protected $version = 'v1';
|
||||||
|
@ -59,7 +61,8 @@ class RestApiClient
|
||||||
'user_agent' => 'Icinga Web 2.0 - Director',
|
'user_agent' => 'Icinga Web 2.0 - Director',
|
||||||
'method' => strtoupper($method),
|
'method' => strtoupper($method),
|
||||||
'content' => $body,
|
'content' => $body,
|
||||||
'header' => $headers
|
'header' => $headers,
|
||||||
|
'ignore_errors' => true
|
||||||
),
|
),
|
||||||
'ssl' => array(
|
'ssl' => array(
|
||||||
'verify_peer' => false,
|
'verify_peer' => false,
|
||||||
|
@ -70,10 +73,14 @@ class RestApiClient
|
||||||
);
|
);
|
||||||
$context = stream_context_create($opts);
|
$context = stream_context_create($opts);
|
||||||
|
|
||||||
|
$res = file_get_contents($this->url($url), false, $context);
|
||||||
|
if (substr(array_shift($http_response_header), 0, 10) !== 'HTTP/1.1 2') {
|
||||||
|
throw new Exception($res);
|
||||||
|
}
|
||||||
if ($raw) {
|
if ($raw) {
|
||||||
return file_get_contents($this->url($url), false, $context);
|
return $res;
|
||||||
} else {
|
} else {
|
||||||
return RestApiResponse::fromJsonResult(file_get_contents($this->url($url), false, $context));
|
return RestApiResponse::fromJsonResult($res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue