Enhance error handling in saveJsonFile function in index.php. Added checks for JSON encoding and file writing, throwing exceptions with descriptive messages for better debugging and user guidance.

This commit is contained in:
smueller
2026-07-07 12:35:36 +02:00
parent 251575c8b4
commit 24f16e454e

View File

@@ -76,11 +76,15 @@ function loadJsonFile(string $file, array $default): array
function saveJsonFile(string $file, array $data): void function saveJsonFile(string $file, array $data): void
{ {
file_put_contents( $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$file, if ($json === false) {
json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), throw new RuntimeException('Konfiguration konnte nicht kodiert werden.');
LOCK_EX }
);
$written = @file_put_contents($file, $json, LOCK_EX);
if ($written === false) {
throw new RuntimeException('Konfiguration konnte nicht gespeichert werden. Bitte Dateirechte prüfen.');
}
} }
function isAdminLoggedIn(): bool function isAdminLoggedIn(): bool