Files
noVNC/app/error-handler.js
T

67 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-09-30 15:35:33 +02:00
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2019 The noVNC Authors
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
2017-02-28 20:47:02 -05:00
// NB: this should *not* be included as a module until we have
// native support in the browsers, so that our error handler
// can catch script-loading errors.
// No ES6 can be used in this file since it's used for the translation
/* eslint-disable prefer-arrow-callback */
2018-09-06 16:53:40 +02:00
(function _scope() {
2017-02-28 20:47:02 -05:00
"use strict";
// Fallback for all uncought errors
2018-09-06 17:34:15 +02:00
function handleError(event, err) {
2017-02-28 20:47:02 -05:00
try {
2018-05-24 00:27:09 +03:00
const msg = document.getElementById('noVNC_fallback_errormsg');
2017-02-28 20:47:02 -05:00
// Only show the initial error
if (msg.hasChildNodes()) {
return false;
}
2018-05-24 00:27:09 +03:00
let div = document.createElement("div");
2017-02-28 20:47:02 -05:00
div.classList.add('noVNC_message');
2017-03-02 14:20:03 +01:00
div.appendChild(document.createTextNode(event.message));
2017-02-28 20:47:02 -05:00
msg.appendChild(div);
2017-03-02 15:44:30 +01:00
if (event.filename) {
2017-02-28 20:47:02 -05:00
div = document.createElement("div");
div.className = 'noVNC_location';
2018-05-24 00:27:09 +03:00
let text = event.filename;
2017-03-02 15:44:30 +01:00
if (event.lineno !== undefined) {
text += ":" + event.lineno;
if (event.colno !== undefined) {
text += ":" + event.colno;
}
}
div.appendChild(document.createTextNode(text));
2017-02-28 20:47:02 -05:00
msg.appendChild(div);
}
2018-03-21 15:33:14 +01:00
if (err && err.stack) {
2017-02-28 20:47:02 -05:00
div = document.createElement("div");
div.className = 'noVNC_stack';
div.appendChild(document.createTextNode(err.stack));
msg.appendChild(div);
}
document.getElementById('noVNC_fallback_error')
.classList.add("noVNC_open");
} catch (exc) {
document.write("noVNC encountered an error.");
}
// Don't return true since this would prevent the error
// from being printed to the browser console.
return false;
}
2018-09-06 16:53:40 +02:00
window.addEventListener('error', function onerror(evt) { handleError(evt, evt.error); });
window.addEventListener('unhandledrejection', function onreject(evt) { handleError(evt.reason, evt.reason); });
2017-02-28 20:47:02 -05:00
})();