feat(админка): client-error без PII

This commit is contained in:
anor
2026-11-06 23:17:08 +10:00
parent 3596ff544c
commit bff50e3eb2
10 changed files with 203 additions and 1 deletions
+18
View File
@@ -42,3 +42,21 @@ const App = () => html`
</div>`;
render(html`<${App} />`, document.getElementById('app'));
// P4.8: ошибки браузера — без PII, не мешают работе страницы.
function reportClientError(message, stack) {
if (!localStorage.getItem('token')) return;
try {
fetch('/api/client-error', {
method: 'POST',
headers: {'Content-Type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem('token')},
body: JSON.stringify({message: String(message).slice(0, 2000),
stack: String(stack || '').slice(0, 2000),
path: location.pathname}),
}).catch(() => {});
} catch (e) { /* отчёт об ошибке не должен ронять страницу */ }
}
window.addEventListener('error', (e) => reportClientError(e.message, e.error && e.error.stack));
window.addEventListener('unhandledrejection', (e) =>
reportClientError(e.reason && e.reason.message || e.reason, e.reason && e.reason.stack));
+11
View File
@@ -36,6 +36,8 @@ export function SystemPage() {
note=${'проверено ' + when(data.generated_at)} />
<${Card} title="Настройки" value=${data.settings.length} note="только чтение" />
<${Card} title="События" value=${data.history.length} note="последние 50" />
<${Card} title="Ошибки браузера" value=${data.errors ? data.errors.total : 0}
note="за 7 дней, PII вычищены" />
</div>
<section class="card">
<h2>Каналы</h2>
@@ -68,6 +70,15 @@ export function SystemPage() {
}}>Отозвать</button>`},
]} rows=${sessions.map((r) => ({...r, key: r.jti}))} empty="Сессий нет" />
</section>
<section class="card">
<h2>Ошибки браузера</h2>
${data.errors && data.errors.items.length ? html`<${Table} columns=${[
{key: 'ts', label: 'Когда', render: (r) => when(r.ts)},
{key: 'message', label: 'Сообщение'},
{key: 'path', label: 'Где'},
]} rows=${data.errors.items.map((r, i) => ({...r, key: r.id || i}))} empty="Ошибок нет" />`
: html`<p class="note">Ошибок нет.</p>`}
</section>
<section class="card">
<h2>История</h2>
<${Table} columns=${[