]>
git.proxmox.com Git - mirror_novnc.git/blob - 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.
5 // No ES6 can be used in this file since it's used for the translation
6 /* eslint-disable prefer-arrow-callback */
11 // Fallback for all uncought errors
12 function handleError (event
, err
) {
14 const msg
= document
.getElementById('noVNC_fallback_errormsg');
16 // Only show the initial error
17 if (msg
.hasChildNodes()) {
21 let div
= document
.createElement("div");
22 div
.classList
.add('noVNC_message');
23 div
.appendChild(document
.createTextNode(event
.message
));
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
;
36 div
.appendChild(document
.createTextNode(text
));
40 if (err
&& err
.stack
) {
41 div
= document
.createElement("div");
42 div
.className
= 'noVNC_stack';
43 div
.appendChild(document
.createTextNode(err
.stack
));
47 document
.getElementById('noVNC_fallback_error')
48 .classList
.add("noVNC_open");
50 document
.write("noVNC encountered an error.");
52 // Don't return true since this would prevent the error
53 // from being printed to the browser console.
56 window
.addEventListener('error', function (evt
) { handleError(evt
, evt
.error
); });
57 window
.addEventListener('unhandledrejection', function (evt
) { handleError(evt
.reason
, evt
.reason
); });