]> git.proxmox.com Git - mirror_novnc.git/blame - app/error-handler.js
Use monospace font for unhandled errors
[mirror_novnc.git] / app / error-handler.js
CommitLineData
adfc9d3f
SR
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
6(function(){
7 "use strict";
8
adfc9d3f
SR
9 // Fallback for all uncought errors
10 function handleError (event, err) {
11 try {
12 const msg = document.getElementById('noVNC_fallback_errormsg');
13
14 // Only show the initial error
15 if (msg.hasChildNodes()) {
16 return false;
17 }
18
19 var div = document.createElement("div");
20 div.classList.add('noVNC_message');
c361080b 21 div.appendChild(document.createTextNode(event.message));
adfc9d3f
SR
22 msg.appendChild(div);
23
24 if (event.filename !== undefined && event.lineno !== undefined && event.colno !== undefined) {
25 div = document.createElement("div");
26 div.className = 'noVNC_location';
27 const text = event.filename + ":" + event.lineno + ":" + event.colno;
28 div.appendChild(document.createTextNode(text));
29 msg.appendChild(div);
30 }
31
32 if ((err !== undefined) &&
33 (err.stack !== undefined)) {
34 div = document.createElement("div");
35 div.className = 'noVNC_stack';
36 div.appendChild(document.createTextNode(err.stack));
37 msg.appendChild(div);
38 }
39
40 document.getElementById('noVNC_fallback_error')
41 .classList.add("noVNC_open");
42 } catch (exc) {
43 document.write("noVNC encountered an error.");
44 }
45 // Don't return true since this would prevent the error
46 // from being printed to the browser console.
47 return false;
48 }
49 window.addEventListener('error', function (evt) { handleError(evt, evt.error); });
50 window.addEventListener('unhandledrejection', function (evt) { handleError(evt.reason, evt.reason); });
51})();