Enhance API error handling and response structure; update app name retrieval method

This commit is contained in:
marc-go committed 2026-10-10 19:23:11 +02:00
1 parent 95f8e22f11
commit eb67458ab1
9 files changed
+38 -9

No files matched your search

+2 -1
View File
@@ -40,7 +40,7 @@ class gbAPI {
"error_text" => "Authentication failed."
];
$this->answer($status, $data);
$this->answer($status, $data, true);
}
}
}
@@ -181,6 +181,7 @@ class gbAPI {
// Check if request is internal or external
if ($this->internal) {
$this->response = $return;
return;
}else{
http_response_code($status);
header("Content-Type: application/json; charset=UTF-8");
+1
View File
@@ -18,6 +18,7 @@ if (!isset($input["username"]) || !isset($input["password"])) {
"error" => "missing_fields",
"error_text" => "Some fields are missing"
], true);
return;
}
$username = $input["username"];
+2 -1
View File
@@ -16,7 +16,8 @@ if (!isset($input["name"]) || !isset($input["text"])) {
$api->answer(400, [
"error" => "missing_fields",
"error_text" => "Some fields are missing"
]);
], true);
return;
}
$html_allowed = $api->getSetting("allow_html");
+1
View File
@@ -21,6 +21,7 @@ if (!$result) {
"entrys" => [],
"empty" => true
]);
return;
}
foreach($result as $row) {
+2 -3
View File
@@ -11,9 +11,8 @@ require_once API_DIR . "api.php";
$api = new gbAPI(false, $internal);
// Get App Name
$command = "SELECT name, value FROM settings WHERE name = :name";
$result = $api->dbCommand($command, true, true, [":name" => "application_name"]);
$result = $api->getSetting("application_name");
$api->answer(200, [
"application_name" => $result[0]["value"]
"application_name" => $result
]);
+4
View File
@@ -18,6 +18,7 @@ if (!isset($input["username"]) || !isset($input["password"]) || !isset($input["p
"error" => "missing_fields",
"error_text" => "Some fields are missing"
]);
return;
}
// Check if application already configurated
@@ -26,6 +27,7 @@ if (is_file(APP_PATH . "database.db")) {
"error" => "already_configurated",
"error_text" => "The application is already configurated."
]);
return;
}
// Check PDO drivers
@@ -34,6 +36,7 @@ if (!extension_loaded("pdo_sqlite") || !extension_loaded("sqlite3")) {
"error" => "missing_drives",
"error_text" => "Please install the extensions pdo_sqlite and sqlite3."
]);
return;
}
$username = $input["username"];
@@ -46,6 +49,7 @@ if ($password !== $password_repeat) {
"error" => "passwords_dont_match",
"error_text" => "The passwords does not match."
]);
return;
}
// Hash Password