diff --git a/src/core/Database.php b/src/core/Database.php index b741b05..410fe56 100644 --- a/src/core/Database.php +++ b/src/core/Database.php @@ -18,17 +18,19 @@ trait Database private static function connect(): PDO { $string = "mysql:hostname=" . DB_HOST . ";dbname=" . DB_NAME; - $pdo_object = new PDO($string, DB_USERNAME, DB_PASSWORD); - try { + return new PDO($string, DB_USERNAME, DB_PASSWORD); } catch (PDOException $e) { - // TODO: Create a page to display the error - Utility::show( - $e - ); - die(); + // if PHPUnit is not running, handle the exception + if (!defined('PHPUNIT_STEAMY_TESTSUITE')) { + // TODO: Display a user-friendly error message + Utility::show("Sorry, we're unable to process your request at the moment. Please try again later."); + die(); + } else { + // if PHPUnit is running, re-throw the exception to allow it to propagate + throw $e; + } } - return $pdo_object; } /**