overhauled error check
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
eb56d78a9e
commit
28b2738c3e
@ -15,15 +15,14 @@ class CheckController
|
||||
* @param String $apiKey
|
||||
* @param String $command
|
||||
*
|
||||
* @return bool|array
|
||||
* @return String
|
||||
*/
|
||||
function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command) : Bool|Array
|
||||
function sendCommand(String $serverName, int $versionIP, String $apiKey, String $command): String
|
||||
{
|
||||
$result = false;
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, option: CURLOPT_URL, value: "https://$serverName/api/v2/" . $command);
|
||||
curl_setopt($curl, option: CURLOPT_RETURNTRANSFER, value: 1);
|
||||
curl_setopt($curl, option: CURLOPT_TIMEOUT_MS, value: 2000);
|
||||
curl_setopt($curl, option: CURLOPT_TIMEOUT_MS, value: 1000);
|
||||
|
||||
if ($versionIP == 4) {
|
||||
curl_setopt($curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V4);
|
||||
@ -41,26 +40,23 @@ class CheckController
|
||||
$apiResult = json_decode($resultJSON);
|
||||
if ($command == "ping" ) {
|
||||
if ($apiResult->response == "pong") {
|
||||
$result = true;
|
||||
$result = $apiResult->response;
|
||||
} else {
|
||||
print("Error: $httpResponse" . PHP_EOL);
|
||||
$result = $resultJSON;
|
||||
}
|
||||
} else {
|
||||
$result = $apiResult;
|
||||
$result = $resultJSON;
|
||||
}
|
||||
break;
|
||||
case 401:
|
||||
print("Missing or wrong API Key" . PHP_EOL);
|
||||
$result = 'Missing or wrong API Key';
|
||||
break;
|
||||
default:
|
||||
print("Unhandled error: " . $httpResponse . PHP_EOL);
|
||||
$result = 'Unhandled error: ' . $httpResponse;
|
||||
}
|
||||
|
||||
} else {
|
||||
$error = curl_error($curl);
|
||||
print("Unknown error: $error" . PHP_EOL);
|
||||
$result = curl_error($curl);
|
||||
}
|
||||
|
||||
curl_close($curl);
|
||||
return $result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user