feat(админка): client-error без PII
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user