@@ -127,7 +127,8 @@ discard block |
||
| 127 | 127 | public function invoke($method, $command, $options = []) |
| 128 | 128 | { |
| 129 | 129 | $result = $this->rawRequest($method, '/CMD_API_' . $command, $options); |
| 130 | - if (!empty($result['error'])) { |
|
| 130 | + if (!empty($result['error'])) |
|
| 131 | + { |
|
| 131 | 132 | throw new DirectAdminException("$method to $command failed: $result[details] ($result[text])"); |
| 132 | 133 | } |
| 133 | 134 | return Conversion::sanitizeArray($result); |
@@ -155,14 +156,18 @@ discard block |
||
| 155 | 156 | */ |
| 156 | 157 | private function rawRequest($method, $uri, $options) |
| 157 | 158 | { |
| 158 | - try { |
|
| 159 | + try |
|
| 160 | + { |
|
| 159 | 161 | $response = $this->connection->request($method, $uri, $options); |
| 160 | - if ($response->getHeader('Content-Type')[0] == 'text/html') { |
|
| 162 | + if ($response->getHeader('Content-Type')[0] == 'text/html') |
|
| 163 | + { |
|
| 161 | 164 | throw new DirectAdminException("DirectAdmin API returned a text/html body. Requested {$uri} via {$method}. Responded: " . strip_tags($response->getBody()->getContents())); |
| 162 | 165 | } |
| 163 | 166 | $body = $response->getBody()->getContents(); |
| 164 | 167 | return Conversion::responseToArray($body); |
| 165 | - } catch (TransferException $exception) { |
|
| 168 | + } |
|
| 169 | + catch (TransferException $exception) |
|
| 170 | + { |
|
| 166 | 171 | // Rethrow anything that causes a network issue |
| 167 | 172 | throw new DirectAdminException("Request to {$uri} using {$method} failed", 0, $exception); |
| 168 | 173 | } |