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:
14
index.php
14
index.php
@@ -76,11 +76,15 @@ function loadJsonFile(string $file, array $default): array
|
||||
|
||||
function saveJsonFile(string $file, array $data): void
|
||||
{
|
||||
file_put_contents(
|
||||
$file,
|
||||
json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
|
||||
LOCK_EX
|
||||
);
|
||||
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
if ($json === false) {
|
||||
throw new RuntimeException('Konfiguration konnte nicht kodiert werden.');
|
||||
}
|
||||
|
||||
$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
|
||||
|
||||
Reference in New Issue
Block a user