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));