-
Notifications
You must be signed in to change notification settings - Fork 17
/
globalErrorHandler.ts
90 lines (75 loc) · 2.37 KB
/
globalErrorHandler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { setErrorTicketId } from 'fm3/actions/mainActions';
import { MyStore } from './storeCreator';
let store: MyStore;
export function setStore(s: MyStore): void {
store = s;
}
(Error.prototype as any).toJSON = function toJSON() {
return {
name: this.name,
message: this.message,
fileName: this.fileName,
lineNumber: this.lineNumber,
columnNumber: this.columnNumber,
description: this.description, // MS
number: this.number, // MS
stack: this.stack,
};
};
window.addEventListener('error', (evt) => {
sendError({
kind: 'global',
message: evt.message,
filename: evt.filename,
lineno: evt.lineno,
colno: evt.colno,
error: evt.error,
});
});
interface ErrorDetails {
kind: string;
action?: unknown;
error: unknown;
message?: string;
filename?: string;
lineno?: number;
colno?: number;
}
export function sendError(errDetails: ErrorDetails): void {
// filter out old browsers
if (!Array.prototype.flatMap) {
return;
}
console.error('Application error');
console.error(errDetails);
const eventId = window.Sentry.captureException(errDetails.error);
window._paq.push(['trackEvent', 'Main', 'error', eventId]);
if (errDetails.message === 'Script error.' || errDetails.filename === '') {
// don't show to user
} else {
handle(eventId);
}
}
function handle(id?: string) {
if (store) {
store.dispatch(setErrorTicketId(id));
} else {
document.body.innerHTML = `
<h1>Application error</h1>
<p>Ticket ID: ${id}.</p>
<p>You can send ticket ID and steps how to reproduce the error to <a href="mailto:[email protected]">[email protected]</a>.</p>
<h1>Chyba aplikácie</h1>
<p>ID incidentu: ${id}.</p>
<p>Na <a href="mailto:[email protected]">[email protected]</a> nám môžete zaslať toto ID a kroky, ako sa vám to podarilo.</p>
<h1>Alkalmazáshiba</h1>
<p>Jegyazonosító (ticket ID): ${id}.</p>
<p>
A jegyazonosítót és a hiba újbóli megjelenéséhez vezető lépések leírását a következő e-mail címre küldheti:
<a href="mailto:[email protected]">[email protected]</a>.
</p>
<h1>Errore dell'applicazione</h1>
<p>Ticket Nr.: ${id}.</p>
<p>Puoi inviare il tuo numero di ticket e i passaggi per riprodurre l'errore a <a href="mailto:[email protected]">[email protected]</a>.</p>
`;
}
}