diff --git a/chandler/Database/DatabaseConnection.php b/chandler/Database/DatabaseConnection.php index b530b88..d4d2bcc 100644 --- a/chandler/Database/DatabaseConnection.php +++ b/chandler/Database/DatabaseConnection.php @@ -13,8 +13,16 @@ class DatabaseConnection private function __construct(string $dsn, string $user, string $password, ?string $tmpFolder = NULL) { + try { + $connection = new Database\Connection($dsn, $user, $password); + } catch(Database\ConnectionException $ex) { + if($ex->getCode() === "42000") + chandler_db_busy(); + else + chandler_http_panic(503, "Service Temporarily Unavailable", "Error estabilishing database connection."); + } + $storage = new FileStorage($tmpFolder ?? (CHANDLER_ROOT . "/tmp/cache/database")); - $connection = new Database\Connection($dsn, $user, $password); $structure = new Database\Structure($connection, $storage); $conventions = new DiscoveredConventions($structure); $context = new Database\Context($connection, $structure, $conventions, $storage); diff --git a/chandler/procedural/db_busy.php b/chandler/procedural/db_busy.php new file mode 100644 index 0000000..a5472c7 --- /dev/null +++ b/chandler/procedural/db_busy.php @@ -0,0 +1,55 @@ + + * @return void + */ +function chandler_db_busy(): void +{ + $errPage = <<<'EOE' + +
+ +