]> git.proxmox.com Git - mirror_novnc.git/blame - app/error-handler.js
Merge pull request #1011 from juanjoDiaz/remove_console_statements
[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 {
858ea4a7 12 var msg = document.getElementById('noVNC_fallback_errormsg');
adfc9d3f
SR
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
732233ed 24 if (event.filename) {
adfc9d3f
SR
25 div = document.createElement("div");
26 div.className = 'noVNC_location';
732233ed
PO
27 var text = event.filename;
28 if (event.lineno !== undefined) {
29 text += ":" + event.lineno;
30 if (event.colno !== undefined) {
31 text += ":" + event.colno;
32 }
33 }
34 div.appendChild(document.createTextNode(text));
adfc9d3f
SR
35 msg.appendChild(div);
36 }
37
5a3e9d3d 38 if (err && (err.stack !== undefined)) {
adfc9d3f
SR
39 div = document.createElement("div");
40 div.className = 'noVNC_stack';
41 div.appendChild(document.createTextNode(err.stack));
42 msg.appendChild(div);
43 }
44
45 document.getElementById('noVNC_fallback_error')
46 .classList.add("noVNC_open");
47 } catch (exc) {
48 document.write("noVNC encountered an error.");
49 }
50 // Don't return true since this would prevent the error
51 // from being printed to the browser console.
52 return false;
53 }
54 window.addEventListener('error', function (evt) { handleError(evt, evt.error); });
55 window.addEventListener('unhandledrejection', function (evt) { handleError(evt.reason, evt.reason); });
56})();