index.php: catch bootstrap exceptions and render a non-fatal warning
Per the spec's error-handling section, all exceptions must be caught at the top of index.php's bootstrap path so a single bad page (CurlError, JsonData, ApiValidation, ApiKeyMissing, LogEntryIncomplete) does not take down the whole UI. The page now renders whatever data is in the DB plus a warning banner with the exception message (htmlspecialchars-escaped to avoid XSS). On the first-run backfill path, the redirect is still emitted inside the try block so the success path is unchanged.
This commit is contained in:
@@ -13,15 +13,22 @@
|
||||
require_once __DIR__ . '/config.php';
|
||||
require_once __DIR__ . '/functions.php';
|
||||
|
||||
if (dbNew()) {
|
||||
$bootstrapWarning = null;
|
||||
|
||||
try {
|
||||
if (dbNew()) {
|
||||
foreach (USER_KEYS as $key => $value) {
|
||||
backfillUserLogs($key);
|
||||
}
|
||||
header('Location: /');
|
||||
} else {
|
||||
exit;
|
||||
} else {
|
||||
foreach (USER_KEYS as $key => $value) {
|
||||
syncUserLogs($key);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$bootstrapWarning = $e->getMessage();
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -45,6 +52,10 @@ if (dbNew()) {
|
||||
<body>
|
||||
<h1>Torn Vault Tracker</h1>
|
||||
|
||||
<?php if ($bootstrapWarning !== null): ?>
|
||||
<div class="warning" style="background:#f77e82;color:#000;padding:.5em 1em;margin:1em 0;border:1px solid #333;">Warning: failed to fetch latest logs from Torn — showing cached data. (<?php echo htmlspecialchars($bootstrapWarning, ENT_QUOTES, 'UTF-8'); ?>)</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="grid">
|
||||
<div class="gridLeft">
|
||||
<h1>Transactions</h1>
|
||||
|
||||
Reference in New Issue
Block a user