From 439d658d14c3775acf21d12066ee48e5279116e9 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 4 Jun 2024 13:20:43 +0200 Subject: [PATCH] Refactor error handling for command execution - Added try-catch block to handle exceptions during command execution. --- index.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 4c3944e..483e467 100644 --- a/index.php +++ b/index.php @@ -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();