forked from kamba4/sunders
fix: Handles issue where error handler was skipped, if database DNS request fails
This commit is contained in:
parent
907c20bad2
commit
590fb8647a
1 changed files with 21 additions and 19 deletions
|
|
@ -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;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue