|
5 | 5 | use GuzzleHttp\Client as GuzzleClient;
|
6 | 6 | use GuzzleHttp\Exception\RequestException;
|
7 | 7 | use GuzzleHttp\Message\Response;
|
| 8 | +use Nitrapi\Common\Exceptions\NitrapiConcurrencyException; |
8 | 9 | use Nitrapi\Common\Exceptions\NitrapiException;
|
9 | 10 | use Nitrapi\Common\Exceptions\NitrapiHttpErrorException;
|
| 11 | +use Nitrapi\Common\Exceptions\NitrapiMaintenanceException; |
10 | 12 |
|
11 | 13 | class Client extends GuzzleClient
|
12 | 14 | {
|
@@ -45,6 +47,12 @@ public function dataGet($url, $headers = null, $options = array()) {
|
45 | 47 | if ($e->hasResponse()) {
|
46 | 48 | $response = $e->getResponse()->json();
|
47 | 49 | $msg = isset($response['message']) ? $response['message'] : 'Unknown error';
|
| 50 | + if ($e->getResponse()->getStatusCode() == 503) { |
| 51 | + throw new NitrapiMaintenanceException(); |
| 52 | + } |
| 53 | + if ($e->getResponse()->getStatusCode() == 428) { |
| 54 | + throw new NitrapiConcurrencyException(); |
| 55 | + } |
48 | 56 | throw new NitrapiHttpErrorException($msg);
|
49 | 57 | }
|
50 | 58 | throw new NitrapiHttpErrorException($e->getMessage());
|
@@ -77,6 +85,12 @@ public function dataPost($url, $body = null, $headers = null, $options = array()
|
77 | 85 | if ($e->hasResponse()) {
|
78 | 86 | $response = $e->getResponse()->json();
|
79 | 87 | $msg = isset($response['message']) ? $response['message'] : 'Unknown error';
|
| 88 | + if ($e->getResponse()->getStatusCode() == 503) { |
| 89 | + throw new NitrapiMaintenanceException(); |
| 90 | + } |
| 91 | + if ($e->getResponse()->getStatusCode() == 428) { |
| 92 | + throw new NitrapiConcurrencyException(); |
| 93 | + } |
80 | 94 | throw new NitrapiHttpErrorException($msg);
|
81 | 95 | }
|
82 | 96 | throw new NitrapiHttpErrorException($e->getMessage());
|
@@ -116,6 +130,12 @@ public function dataDelete($url, $body = null, $headers = null, $options = array
|
116 | 130 | if ($e->hasResponse()) {
|
117 | 131 | $response = $e->getResponse()->json();
|
118 | 132 | $msg = isset($response['message']) ? $response['message'] : 'Unknown error';
|
| 133 | + if ($e->getResponse()->getStatusCode() == 503) { |
| 134 | + throw new NitrapiMaintenanceException(); |
| 135 | + } |
| 136 | + if ($e->getResponse()->getStatusCode() == 428) { |
| 137 | + throw new NitrapiConcurrencyException(); |
| 138 | + } |
119 | 139 | throw new NitrapiHttpErrorException($msg);
|
120 | 140 | }
|
121 | 141 | throw new NitrapiHttpErrorException($e->getMessage());
|
|
0 commit comments