Refactor error handling for command execution

- Added try-catch block to handle exceptions during command execution.
This commit is contained in:
Jeroen De Meerleer 2024-06-04 13:20:43 +02:00
parent e004a1002e
commit 439d658d14
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -13,8 +13,12 @@ if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') {
if (isset($submetric['command'])) {
$output = null;
$retval = null;
exec($submetric['command'], $output, $retval);
$output = implode("\n", $output);
try {
exec($submetric['command'], $output, $retval);
$output = implode("\n", $output);
} catch (Exception $e) {
$output = '';
}
} elseif (isset($submetric['http'])) {
$client = new GuzzleHttp\Client();