mirror of
https://github.com/openvk/chandler.git
synced 2024-11-15 03:31:12 +03:00
Add DB overload error pages
This commit is contained in:
parent
3e0637e447
commit
eaba4a25de
2 changed files with 64 additions and 1 deletions
|
@ -13,8 +13,16 @@ class DatabaseConnection
|
||||||
|
|
||||||
private function __construct(string $dsn, string $user, string $password, ?string $tmpFolder = NULL)
|
private function __construct(string $dsn, string $user, string $password, ?string $tmpFolder = NULL)
|
||||||
{
|
{
|
||||||
$storage = new FileStorage($tmpFolder ?? (CHANDLER_ROOT . "/tmp/cache/database"));
|
try {
|
||||||
$connection = new Database\Connection($dsn, $user, $password);
|
$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"));
|
||||||
$structure = new Database\Structure($connection, $storage);
|
$structure = new Database\Structure($connection, $storage);
|
||||||
$conventions = new DiscoveredConventions($structure);
|
$conventions = new DiscoveredConventions($structure);
|
||||||
$context = new Database\Context($connection, $structure, $conventions, $storage);
|
$context = new Database\Context($connection, $structure, $conventions, $storage);
|
||||||
|
|
55
chandler/procedural/db_busy.php
Normal file
55
chandler/procedural/db_busy.php
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ends application and renders DB error page.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
* @author kurotsun <celestine@vriska.ru>
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function chandler_db_busy(): void
|
||||||
|
{
|
||||||
|
$errPage = <<<'EOE'
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
position: relative;
|
||||||
|
height: 100vh;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
#dbErrorBody {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
margin-right: -50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
width: 400px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
#dbErrorBody h1 {
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
#dbErrorBody span {
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
#dbErrorBody img {
|
||||||
|
max-width: 128px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<title>Resource Busy | Chandler App Server</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="dbErrorBody">
|
||||||
|
<img src="https://i.imgur.com/N2Ix4fI.png" alt="Database Error">
|
||||||
|
<h1>Service Unavailable</h1>
|
||||||
|
<span>Server can't proccess your request at this moment. Please try again later. Sorry for that.</span>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOE;
|
||||||
|
|
||||||
|
header("HTTP/1.1 503 Service Unavailable");
|
||||||
|
exit($errPage);
|
||||||
|
}
|
Loading…
Reference in a new issue