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,27 +2,29 @@
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) { throw new Exception("Could not connect to database");
http_response_code(503);
header('Content-type: application/json');
$result = '{"error":"Database unavailable"}';
echo $result;
exit;
}
$syncstate_querry = $mysqli->query("SELECT * FROM sync_state WHERE k = 'sequenceNumber'");
while($row = $syncstate_querry->fetch_assoc()) {
$syncstate = array('sequenceNumber' => $row["v"]);
} }
$result = json_encode($syncstate); $syncstate_querry = $mysqli->query("SELECT * FROM sync_state WHERE k = 'sequenceNumber'");
$mysqli->close(); while($row = $syncstate_querry->fetch_assoc()) {
$syncstate = array('sequenceNumber' => $row["v"]);
}
header('Content-type: application/json; Charset : utf-8'); $result = json_encode($syncstate);
echo $result;
$mysqli->close();
header('Content-type: application/json; Charset : utf-8');
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;
}
?> ?>