Skip to content

Commit

Permalink
Merge pull request #33 from keepwn/master
Browse files Browse the repository at this point in the history
Add an exception being thrown when proxmox return status_code >= 400
  • Loading branch information
GothShoot authored Feb 3, 2022
2 parents e8e5ad8 + e71a1cb commit 621c405
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Exception/BadResponseException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* This file is part of the ProxmoxVE PHP API wrapper library (unofficial).
*
* @copyright 2014 César Muñoz <[email protected]>
* @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 <[email protected]>
*/
class BadResponseException extends \RuntimeException
{
}
5 changes: 5 additions & 0 deletions src/Proxmox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 621c405

Please sign in to comment.