diff --git a/src/Exception/BadResponseException.php b/src/Exception/BadResponseException.php new file mode 100644 index 0000000..34da81a --- /dev/null +++ b/src/Exception/BadResponseException.php @@ -0,0 +1,20 @@ + + * @license http://opensource.org/licenses/MIT The MIT License. + */ + +namespace ProxmoxVE\Exception; + +/** + * BadResponseException class. Is the exception thrown when proxmox + * return status_code >= 400, thus the ProxmoxVE API client can not be used. + * + * @author César Muñoz + */ +class BadResponseException extends \RuntimeException +{ +} diff --git a/src/Proxmox.php b/src/Proxmox.php index d192072..b04bf2f 100644 --- a/src/Proxmox.php +++ b/src/Proxmox.php @@ -14,6 +14,7 @@ use GuzzleHttp\Psr7\Request; use ProxmoxVE\Exception\AuthenticationException; +use ProxmoxVE\Exception\BadResponseException; /** * ProxmoxVE class. In order to interact with the proxmox server, the desired @@ -154,6 +155,10 @@ private function processHttpResponse($response) return null; } + if ($response->getStatusCode() >= 400) { + throw new BadResponseException($response->getReasonPhrase()); + } + switch ($this->fakeType) { case 'pngb64': $base64 = base64_encode($response->getBody());