fix: Handles issue where error handler was skipped, if database DNS request fails

This commit is contained in:
Vincent Mahnke 2025-11-01 21:28:30 +01:00
commit 590fb8647a
Signed by: ViMaSter
GPG key ID: 6D787326BA7D6469

View file

@ -2,15 +2,10 @@
error_reporting(0); error_reporting(0);
include $pathToWebFolder.'config.php'; include $pathToWebFolder.'config.php';
try {
/* Connect to database */
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB); $mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
if($mysqli->connect_errno) { if($mysqli->connect_errno) {
http_response_code(503); throw new Exception("Could not connect to database");
header('Content-type: application/json');
$result = '{"error":"Database unavailable"}';
echo $result;
exit;
} }
$syncstate_querry = $mysqli->query("SELECT * FROM sync_state WHERE k = 'sequenceNumber'"); $syncstate_querry = $mysqli->query("SELECT * FROM sync_state WHERE k = 'sequenceNumber'");
@ -25,4 +20,11 @@
header('Content-type: application/json; Charset : utf-8'); header('Content-type: application/json; Charset : utf-8');
echo $result; echo $result;
mysqli_report(MYSQLI_REPORT_OFF);
} catch (Exception $e) {
http_response_code(503);
header('Content-type: application/json');
$result = '{"error":"Database unavailable"}';
echo $result;
}
?> ?>