]> git.proxmox.com Git - mirror_novnc.git/blob - app/error-handler.js
Use fat arrow functions `const foo = () => { ... };` for callbacks
[mirror_novnc.git] / app / error-handler.js
1 // NB: this should *not* be included as a module until we have
2 // native support in the browsers, so that our error handler
3 // can catch script-loading errors.
4
5 // No ES6 can be used in this file since it's used for the translation
6 /* eslint-disable prefer-arrow-callback */
7
8 (function() {
9 "use strict";
10
11 // Fallback for all uncought errors
12 function handleError (event, err) {
13 try {
14 const msg = document.getElementById('noVNC_fallback_errormsg');
15
16 // Only show the initial error
17 if (msg.hasChildNodes()) {
18 return false;
19 }
20
21 let div = document.createElement("div");
22 div.classList.add('noVNC_message');
23 div.appendChild(document.createTextNode(event.message));
24 msg.appendChild(div);
25
26 if (event.filename) {
27 div = document.createElement("div");
28 div.className = 'noVNC_location';
29 let text = event.filename;
30 if (event.lineno !== undefined) {
31 text += ":" + event.lineno;
32 if (event.colno !== undefined) {
33 text += ":" + event.colno;
34 }
35 }
36 div.appendChild(document.createTextNode(text));
37 msg.appendChild(div);
38 }
39
40 if (err && err.stack) {
41 div = document.createElement("div");
42 div.className = 'noVNC_stack';
43 div.appendChild(document.createTextNode(err.stack));
44 msg.appendChild(div);
45 }
46
47 document.getElementById('noVNC_fallback_error')
48 .classList.add("noVNC_open");
49 } catch (exc) {
50 document.write("noVNC encountered an error.");
51 }
52 // Don't return true since this would prevent the error
53 // from being printed to the browser console.
54 return false;
55 }
56 window.addEventListener('error', function (evt) { handleError(evt, evt.error); });
57 window.addEventListener('unhandledrejection', function (evt) { handleError(evt.reason, evt.reason); });
58 })();