From eaba4a25de80f663d9a8581dba3ef4a7689da9d3 Mon Sep 17 00:00:00 2001 From: Jill Stingray Date: Wed, 17 Jun 2020 21:46:52 +0300 Subject: [PATCH] Add DB overload error pages --- chandler/Database/DatabaseConnection.php | 10 ++++- chandler/procedural/db_busy.php | 55 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 chandler/procedural/db_busy.php 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' + + + + Resource Busy | Chandler App Server + + +
+ Database Error +

Service Unavailable

+ Server can't proccess your request at this moment. Please try again later. Sorry for that. +
+ + +EOE; + + header("HTTP/1.1 503 Service Unavailable"); + exit($errPage); +}