From caa51cc020dac1add0368a563426d8d26a5b3e2b Mon Sep 17 00:00:00 2001 From: Serge Kraev Date: Wed, 7 Aug 2019 16:25:57 +0300 Subject: [PATCH 1/2] adds the ability to throw http exceptions --- src/Proxmox.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Proxmox.php b/src/Proxmox.php index 85cc431..4f6e32d 100644 --- a/src/Proxmox.php +++ b/src/Proxmox.php @@ -27,6 +27,11 @@ class Proxmox * @var \GuzzleHttp\Client() */ private $httpClient; + + /** + * @var bool + */ + private $throwHttpExceptions = false; /** * Contains the proxmox server authentication data. @@ -79,7 +84,8 @@ class Proxmox public function __construct( $credentials, $responseType = 'array', - $httpClient = null + $httpClient = null, + $throwHttpExceptions = false ) { $this->setHttpClient($httpClient); @@ -87,6 +93,8 @@ public function __construct( $this->setCredentials($credentials); $this->setResponseType($responseType); + + $this->throwHttpExceptions = $throwHttpExceptions; } @@ -116,7 +124,7 @@ private function requestResource($actionPath, $params = [], $method = 'GET') case 'GET': return $this->httpClient->get($url, [ 'verify' => false, - 'exceptions' => false, + 'exceptions' => $this->throwHttpExceptions, 'cookies' => $cookies, 'query' => $params, ]); @@ -128,7 +136,7 @@ private function requestResource($actionPath, $params = [], $method = 'GET') ]; return $this->httpClient->request($method, $url, [ 'verify' => false, - 'exceptions' => false, + 'exceptions' => $this->throwHttpExceptions, 'cookies' => $cookies, 'headers' => $headers, 'form_params' => $params, @@ -150,6 +158,7 @@ private function requestResource($actionPath, $params = [], $method = 'GET') */ private function processHttpResponse($response) { + var_dump($response); if ($response === null) { return null; } @@ -193,7 +202,7 @@ public function login() $loginUrl = $this->credentials->getApiUrl() . '/json/access/ticket'; $response = $this->httpClient->post($loginUrl, [ 'verify' => false, - 'exceptions' => false, + 'exceptions' => $this->throwHttpExceptions, 'form_params' => [ 'username' => $this->credentials->getUsername(), 'password' => $this->credentials->getPassword(), From 7598c296e081fc2634c6a5ba29405009d1130533 Mon Sep 17 00:00:00 2001 From: Serge Kraev Date: Wed, 7 Aug 2019 16:30:24 +0300 Subject: [PATCH 2/2] cleanup --- src/Proxmox.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Proxmox.php b/src/Proxmox.php index 4f6e32d..1ed6957 100644 --- a/src/Proxmox.php +++ b/src/Proxmox.php @@ -158,7 +158,6 @@ private function requestResource($actionPath, $params = [], $method = 'GET') */ private function processHttpResponse($response) { - var_dump($response); if ($response === null) { return null; }