Skip to content

Commit 621c405

Browse files
authored
Merge pull request #33 from keepwn/master
Add an exception being thrown when proxmox return status_code >= 400
2 parents e8e5ad8 + e71a1cb commit 621c405

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the ProxmoxVE PHP API wrapper library (unofficial).
5+
*
6+
* @copyright 2014 César Muñoz <[email protected]>
7+
* @license http://opensource.org/licenses/MIT The MIT License.
8+
*/
9+
10+
namespace ProxmoxVE\Exception;
11+
12+
/**
13+
* BadResponseException class. Is the exception thrown when proxmox
14+
* return status_code >= 400, thus the ProxmoxVE API client can not be used.
15+
*
16+
* @author César Muñoz <[email protected]>
17+
*/
18+
class BadResponseException extends \RuntimeException
19+
{
20+
}

src/Proxmox.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use GuzzleHttp\Psr7\Request;
1515

1616
use ProxmoxVE\Exception\AuthenticationException;
17+
use ProxmoxVE\Exception\BadResponseException;
1718

1819
/**
1920
* ProxmoxVE class. In order to interact with the proxmox server, the desired
@@ -154,6 +155,10 @@ private function processHttpResponse($response)
154155
return null;
155156
}
156157

158+
if ($response->getStatusCode() >= 400) {
159+
throw new BadResponseException($response->getReasonPhrase());
160+
}
161+
157162
switch ($this->fakeType) {
158163
case 'pngb64':
159164
$base64 = base64_encode($response->getBody());

0 commit comments

Comments
 (0)