Simplify error handling

This commit is contained in:
ruan 2022-08-02 06:52:24 +02:00
parent 9cb64a7e8c
commit b77ba15659

View File

@ -81,16 +81,14 @@ class Database {
function handle_error(Settings $cfg, Exception $e) { function handle_error(Settings $cfg, Exception $e) {
if ($cfg->error_throw) throw $e; if ($cfg->error_throw) throw $e;
$message = $e->getMessage(); $message = 'Database error: ' . $e->getMessage();
if ($cfg->error_pages) { if ($cfg->error_pages) {
if (strstr($message, "Access denied for user")) { if (strstr($message, "Access denied for user")) {
if ($cfg->error_reporting) { $param = "";
redirect("error/access-denied.php?error=" . base64_encode($message)); if ($cfg->error_reporting) $param = "?error=" . base64_encode($e->getMessage());
} else { redirect("error/access-denied.php$param");
redirect("error/access-denied.php");
} }
} if (strstr($message, "Base table or view not found:") || strstr($message, "Unknown column")) {
if (strstr($message, "Base table or view not found:")) {
try { try {
$st = $this->conn->query("SELECT * FROM " . $cfg->table['bans'] . " LIMIT 1;"); $st = $this->conn->query("SELECT * FROM " . $cfg->table['bans'] . " LIMIT 1;");
$st->fetch(); $st->fetch();
@ -100,13 +98,8 @@ class Database {
} }
redirect("error/outdated-plugin.php"); redirect("error/outdated-plugin.php");
} }
if (strstr($message, "Unknown column")) {
redirect("error/outdated-plugin.php");
} }
} if (!$cfg->error_reporting) $message = "Database error";
if ($cfg->error_reporting) { die($message);
die("Database error: $message");
}
die("Database error");
} }
} }