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